The project gets built without error from Android Studio -> Build -> Build APKs and after installation it works fine. But running the project with a Run Configuration gives
You can follow any of the following ways to fix the issue:
For Android studio 3.1 or <3.2
android.enableAapt2=false
For Android studio 3.2 or later
android.enableAapt2=true
It is a bug in gradle plugin code that calls AAPT1. It was fixed but not cherry-picked, it should be available in the next released version (it should be fixed in 3.2 canary 3 and newer).
This only affects AAPT1. Removing the android.enableAapt2=false flag will make the code not hit this codepath (check your gradle.properties file and the extra arguments you pass to gradle from Android Studio).
In your gradle properties: remove android.enableAapt2=false, and upgrade the buildToolVersion in your app build.gradle and in all the other modules(if used) too.
Run the command gradlew --info assembleDebug in your terminal and check for other errors and if you find them then manually go and fix them. In my case there was a 9 patch image which was causing all the trouble.
Try to clean and rebuild your project.
Or
Try to disable instant run feature and see if it works.
Or
Try and enable multiDexEnabled.
defaultConfig {
multiDexEnabled true
}
Or
File -> Invalidate caches and restart
Open the File tab and then click on Invalidate Caches \ Restart. It worked for me :).
I did below and it solved this issue:
In gradle.properties file:
android.enableAapt2=false
I disabled the Instant Run.(Important)