Android Studio inline compiler showing red errors, but compilation with gradle works fine
Thanks to free3dom for getting me on the right track here.
Diagnosis
The Sync Project with Gradle Files
option in Android Studio seems to keep the Project Structure
libraries up to date.
However, in my case there were some errors:
Expanding the (not very obvious) link showed the detail. My wire-runtime library was showing in an incorrect location:
This seemed to be a hangover from my original configuration where I had imported the JAR into a libs folder.
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
}
I subsequently changed it to be imported directly from Maven Central (as per here), and it seems that the old setting was never overwritten with the new one.
The Fix
The fix is to delete the library dependency from the Project Structure
screen and then Sync Project with Gradle Files
again.
More Detail
You can also see what path is being used to the resource by opening the .idea/libraries/wire_runtime_1_2_0.xml
directly.
My broken one was:
<component name="libraryTable">
<library name="wire-runtime-1.2.0">
<CLASSES>
<root url="jar://$PROJECT_DIR$/MY_MODULE/libs/wire-runtime-1.2.0.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
After deleting and re-adding the library it changed the root url
to:
<root url="jar://$USER_HOME$/.gradle/caches/artifacts-26/filestore/com.squareup.wire/wire-runtime/1.2.0/jar/44e7acbd5eb6f29698181dc3d67a60acf7efee80/wire-runtime-1.2.0.jar!/" />
Update
Android Studio v0.4.4 apparently fixes other bugs which have the same symptoms, so if you have an older version you may wish to upgrade.
Android Studio errors in files but project compiles and run
SOLUTION:
In build.gradle(Module: app) file, update the dependencies and sync.
Android Studio inline compiler showing red errors, but compilation with gradle works fine
Thanks to free3dom for getting me on the right track here.
Diagnosis
The Sync Project with Gradle Files
option in Android Studio seems to keep the Project Structure
libraries up to date.
However, in my case there were some errors:
Expanding the (not very obvious) link showed the detail. My wire-runtime library was showing in an incorrect location:
This seemed to be a hangover from my original configuration where I had imported the JAR into a libs folder.
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
}
I subsequently changed it to be imported directly from Maven Central (as per here), and it seems that the old setting was never overwritten with the new one.
The Fix
The fix is to delete the library dependency from the Project Structure
screen and then Sync Project with Gradle Files
again.
More Detail
You can also see what path is being used to the resource by opening the .idea/libraries/wire_runtime_1_2_0.xml
directly.
My broken one was:
<component name="libraryTable">
<library name="wire-runtime-1.2.0">
<CLASSES>
<root url="jar://$PROJECT_DIR$/MY_MODULE/libs/wire-runtime-1.2.0.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
After deleting and re-adding the library it changed the root url
to:
<root url="jar://$USER_HOME$/.gradle/caches/artifacts-26/filestore/com.squareup.wire/wire-runtime/1.2.0/jar/44e7acbd5eb6f29698181dc3d67a60acf7efee80/wire-runtime-1.2.0.jar!/" />
Update
Android Studio v0.4.4 apparently fixes other bugs which have the same symptoms, so if you have an older version you may wish to upgrade.
Any android Studio version 3.2.1 show red resource but still compile
I solved it after long other searchs.
Solution :
My problem was i had 3 modules, but 2 of them had the same package name. I rename one and it solved my problem.
How i solved it:
First step, i checked if java files was the problems:
1) I deleted all my .java files
2) Deleted all activity in androidmanifest.xml
3) create a new empty activitySecond step, i checked if xml files was the problem:
1) I deleted all content in my res folder, except the layout of my empty activity
Third step, i checked if gradle library was the problem:
1) I deleted one by one my dependencies in build.gradle
I found that my line who was injected the project in the dependencies was the cause of my problems :
implementation project(':XXX')
1) When i delete it, it was fixed.
2) Therefore, i inspect it and found that if i delete the androidmanifest.xml of XXX project, it solved my problem.
3) Debugging androidmanifest.xml, i found that the id was the problem.
It seems like that androidstudio after 3.2.1 doesn't allow multiple module with same package name. So, now, all my modules have specific package name.
How can I fix errors (red texts) in XML which are preventing from showing preview or running the app on Android Studio?
I kinda tried to close the project and tried to import the project.
Now i can see the the files inside the app java module.
Thank you guys :>>
Related Topics
How to Verify Purchase for Android App in Server Side (Google Play in App Billing V3)
Error Androidmanifest.Xml Doesn't Exist or Has Incorrect Root Tag
Detect or Prevent If User Uses Fake Location
Where Is Android_Sdk_Root and How to Set It.
How to Access /Storage/Emulated/0/
Android Blur View (Blur Background Behind the View)
How to Disable Behind View Click Event Framelayout
Android Check Null or Empty String in Android
How to Know the Mtu Size of Android Smartphone
How to Refresh a Previous Activity After the Back Button Is Pressed
How to Make Android Device Boot When Power Is Plugged In
How to Measure Distance to Object With Camera
Open Facebook Page in Facebook App (If Installed) on Android
How to Completely Rename an Android Application
Navigate from One Fragment to Another on Click of a Button
Strange Outofmemory Issue While Loading an Image to a Bitmap Object