While building for android, sometimes there are errors. I've been working on react-native (these solutions will also work the same for flutter and other android dev languages) for quite sometime now and have faced errors throughtout but I have been documenting them locally so I'm creating this gist which I'll keep up-to-date as I face any new errors. Please note that all the solutions given here worked for me and they might not necessarily work for you so move with caution. Feel free to add your own solution that worked for you,
This occurs when your JDK version is not the same as mentioned in your project. To solve open the project in Android studio, make it finish its processing first then go to Preferences > Build, Execution, Deployment > Build Tools > Gradle and then Gradle Settings and select the correct JDK version i.e. it was JDK 8 in my case. Then try cleaning and building again.
Clean project, clean any build related file on github.
SENSITIVE: For JVM see the there is a folder inside android
named .idea
> modules
> -1032735254(some number like that) > react-native-gradle-plugin.iml
or in VSCode search for jvmTarget
and only one result will show. In this file there will be a line <option name="jvmTarget" value="11" />
is where you can set your JVM version.
If there is an output of OutPut file you can replace that line with import com.android.build.*
In the styles.xml
file inside android > app > src > main > res > values
make sure all is ok syntax-wise. Compare it with earlier version of this file in your code, because I don't remember what exactly was wrong but there was some problem with the syntax of this file.
This error happened because there was not enough space left on my Mac. So, I did a restart of my laptop to clean up some cached space and then build the app and the error was gone.
To fix do cd android
and then do ./gradlew clean
to make it work. For some reason fbsdk
was causing it for me.
In AndroidManifest.xml
file there should be a android:debuggable="true"
comment it and build again.
Look for <style name="SplashTheme" parent="AppTheme">
in styles.xml
and change its item to <item name="android:windowBackground">@android:drawable/splash_screen</item>
ensure that you have splash_screen.xml
file in /res/drawable
.
It happend when I configured firebase for react native project. We have to enable Multidex for android and here is a link that might help: https://rnfirebase.io/enabling-multidex
Just restarting the app build process works sometimes. But also try doing ./gradlew clean
inside android
folder it helps.
On Windows do: cd android
then ./gradlew clean
then cd ..
and then npm cache clean --force
On MacOS do: cd android
then ./gradlew clean
and then cd ..
Deleting all AVDs (Android Virtual Devices) and adding a new one helps in the launching of the simulator at least and there will be a new error and this one will be gone.
Then close android studio and delete manually \app\build
and \app\release
and \app\debug
folders. Runn again!
Occurs when deleted the build
folder in the /android
folder, so check for that.
The error happened to me while installing the React-Native-Image-Picker
library. I was able to solve it like this:
Error:
I accessed this path which appeared to me in the complete error:
..\node_modules\react-native-image-picker\android\build\intermediates\library_manifest\debug\AndroidManifest.xml
When reviewing the file I identified the versions requested by the library:
<uses-sdk android:minSdkVersion="21" android:targetSdkVersion="29" />
I modified in /android/app/build.gradle
the following lines of code:
android {
...
defaultConfig {
...
minSdkVersion 21
targetSdkVersion 29
}
}
The solution is on the path android/app/src/main/res/
delete all directory with start name drawable_*
as well as raw
folder. You can use the commands below inside cd android
as well: rm -rf ./app/src/main/res/drawable-*
and then rm -rf ./app/src/main/res/raw
Try by removing both build
folders in /android
and /android/app.
. If this doesn't work do cd android
&& ./gradlew clean
This occurs when I installed firebase in react-native project. To fix open /android/app/build.gradle
comment the line apply plugin: 'com.google.gms.google-services' and it'll work. This is because com.android.application
package already has the same package.
This error started appearing after I updated the Java. To solve it check the following:
-
Check if the android studio has any updates pending. Update android studio.
-
Open your android project in updated android studio and wait for it to load it might take some time to load. It'll show you a popup that an update is required either click. It'll show if there is an update. In the popup, click Begin Upgrade as shown in the images below:
-
Next, open SDK manager from the android studio the go-to SDK tools, and see if there is anything left to update.
-
Finally, note that the compile, runtime, testCompile, and testRuntime configurations introduced by the Java plugin have been deprecated since Gradle 4.10 (Aug 27, 2018), and were finally removed in Gradle 7.0 (Apr 9, 2021). The aforementioned configurations should be replaced by implementation, runtimeOnly, testImplementation, and testRuntimeOnly, respectively.
-
Then just open your project in android studio and from the file meun select the highlighted one in the image below:
This should fix this error.
This error occurred when building for release .apk and here is how to fix it:
- Delete the apk folder in /app/build/outputs/apk (if building .apk) or bundle folder (if building .abb)
- Make sure you are cd android
- Do rm -rf ./app/src/main/res/drawable-*
- Then rm -rf ./app/src/main/res/raw
- and finally ./gradlew assembleRelease
OR
If the above doesn't work, goto
<your-project-path>/android
and Press Command + Shift + . (period) to show the hiden files. There will be a hidden.gradle
folder, delete that. Then open terminal docd android
and./gradlew clean
Then when you build or run the error will go away.
Check if in /android/gradle.properties
or whereever you have it the MYAPP_UPLOAD_STORE_FILE & MYAPP_UPLOAD_KEY_ALIAS is correct.
Check if you have mis-spelled or mis-placed keystore file.