This is a really previous query, but it surely nonetheless occurs lots and there’s no actually complete reply right here.
I’ve had this drawback extra instances than I wish to admit. It might be attributable to all kinds of points that principally all should do along with your mission construction not matching what’s anticipated. Here’s a listing of all the issues I’ve had:
Importing from Eclipse to Android Studio doesn’t all the time work easily, particularly with older variations of Android Studio. Make positive you are utilizing the proper listing tree. It ought to appear to be this for a reasonably mature app:
AppName/ // AppName is your app's title, clearly .gradle/ // This is a compiler created listing. You ought to usually go away it alone .thought/ // Ditto construct/ // This too gradle/ // And this app/ construct/ libs/ src/ androidTest/ // Tests primarily based on the Android instrumentation runner ought to go right here foremost/ java/ absolutely/ // Typically com certified/ // the area title. Longer bundle // names could have deeper folder timber AppName/ // All your java recordsdata go right here res/ drawable-*/ // One of those for every decision you assist format/ // All of your basic layouts menu/ // All of your menu layouts values/ // All of your useful resource xml recordsdata xml/ // PreferenceScreen layouts go right here AndroidManifest.xml debug/ check/ // Pure jUnit checks ought to go right here .gitignore app.iml construct.gradle // This is the gradle file you ought to be making most modifications to proguard-rules.professional .gitignore construct.gradle // This gradle file ought to principally be left alone gradle.properties gradlew native.properties AppName.iml settings.gradle
It could not appear to be this in your IDE. There is a drop-down above the file tree that shows your recordsdata in alternative ways, and it defaults on my system to 1 referred to as Android that breaks your recordsdata out into their differing kinds. It’s simpler to repair this sort of drawback from the one referred to as Project, and even simpler instantly out of your OS’s file system, as a result of Android Studio collapses folders that solely comprise one other folder onto a single line.
Especially if you happen to ever change the title of your app, it’s worthwhile to guarantee that the supply tree foremost/java/com/area/AppName is up to date. Also guarantee that the bundle tag in your AndroidManifest.xml is right.
If there are errors in both your Gradle recordsdata or your AndroidManifest.xml, this may forestall Android Studio from correctly constructing your useful resource recordsdata. Gradle recordsdata might be damaged by upgrading Android Studio generally, particularly from the pre-1.0 variations. Sometimes it’s because it stops supporting older variations of the Gradle plugin, so it’s worthwhile to replace your model numbers. It can generally be onerous to search out what the present variations are. As of right this moment, 7/17/15, my apps are compiling positive with
com.android.equipment.construct:gradle:1.2.3. This is in the dependencies block in the outermost gradle file,
If your AndroidManifest references a non-existent drawable or string useful resource or exercise, it should break and trigger this error. Sometimes if something references a nonexistent drawable or string useful resource you’ll get this error.
If you may have a file in your assets that’s corrupted, or an invalid xml file, you’ll get this error.
In my expertise, generally Android Studio simply hiccups for no purpose, and it’s worthwhile to restart it and/or your PC. I do not know why, however generally it really works.
If you may have two xml assets with the identical title, in directories that don’t override one another, you may have this drawback. For occasion, you may have the identical title in drawable-mhdpi and drawable-xhdpi as a result of they override one another relying on the goal machine, however in case you have the identical title in format and in menu, it should trigger an issue. Rename or delete one of many recordsdata.
If just some assets are having this drawback, these assets are most probably in the improper listing.
In one case I needed to utterly reinstall Android Studio. I do not know what was improper, but it surely labored.
In one case I moved my whole mission to a distinct listing and re-imported it as a brand new mission. I do not know what was improper, but it surely labored.
Xml recordsdata with reserved phrases for names could cause this drawback. Rename or delete them.
There are a number of methods your Gradle file can find yourself referencing a model of the build-tools that you simply shouldn’t have put in. Correct this by altering Gradle or downloading the suitable build-tools.
Finally, after you have fastened no matter is improper, it’s worthwhile to clear your Gradle mission. You do that by going to the Build menu on the high and choosing Clean Project.