Top Android Errors and Fixes (Android Studio 2023 Updated)

Home » Android » Top Android Errors and Fixes (Android Studio 2023 Updated)

Android errors can be frustrating, don’t you think? Every app developer encounters various types of errors when developing both complex and simple apps. Handling errors can be a demanding task. Android development is never a zone free of errors. You may encounter numerous android errors while developing an app, including lesser-known errors and compatibility issues, among others. In this tutorial, we will explore new and common errors in Android development that may arise in your Android Studio. It can be a lifesaver for you.

Top Android Errors and Fixes (Android Studio 2023 Updated)

1. Android Error : Build Features Issue

In Android Studio :

Error Message

Cause: defaultConfig contains custom BuildConfig fields, but the feature is disabled.

To enable the feature, add the following to your module-level build.gradle:

`android.buildFeatures.buildConfig true`

How to Fix this Android Error in Android Studio?

Step 1: Open build.gradle(app)

Step 2: Enable buildConfig ‘true’

android{

buildFeatures {
    buildConfig = true
}

}

android is typically part of the Gradle build script for an Android app. The android block is used to configure various aspects of your Android app’s build process.

buildConfig = true: By setting buildConfig to true within buildFeatures, you are enabling the automatic generation of a BuildConfig class.

The BuildConfig class is automatically generated by the Android build system and includes various constants and configuration values that you can access in your code.

2. File google-services.json is missing

Message:

Caused by: org.gradle.api.GradleException: File google-services.json is missing. The Google Services Plugin cannot function without it.

The error may only appear if you are using google services or firebase services(AdMob, Google Analytics etc.).

Error Fix:

Step 1: Open Firebase console , and Download the ‘google-services.json’ file.

Project Overview > click on gear icon and select Project settings

Step 2: Choose your app. Click and Download ‘google-services.json’ file.

Step 5: Add this file inside the app folder.

Note: If you don’t want to use the JSON file, you can remove it and make changes in the Gradle file by removing the ‘apply plugin: ‘com.google.gms.google-services‘ statement from build.gradle.

3. App Targeting Android 12 : Manifest merger failed

Message:

java.lang.RuntimeException: Manifest merger failed with multiple errors, see logs
(Caused by: java.lang.RuntimeException: Manifest merger failed with multiple errors, see logs)

This Android error could arise when you target Android 12. It can be easily fixed by enabling ‘exported’ (either true or false) in the Android Manifest file.

Fix

Step1: Open the AndroidManifest file, locate the launcher activity, and set the ‘exported’ option.

<activity 
android:name =".main"
android:label="@string/title_activity_home"
android:theme="@style/BigknolMaterialTheme"
android:exported="true">
     <intent-filter>
              <action android:name="android.intent.action.MAIN" />
              <category android:name="android.intent.category.LAUNCHER" />
     </intent-filter>
  </activity>

4. compileSdkVersion’ is deprecated

It’s not an error. It’s a warning!

The warning or message ‘compileSdkVersion’ is deprecated’ signifies that your current compilation target for the Android SDK (Software Development Kit) is no longer the recommended or up-to-date version.

Fix

Step 1: Open gradle file(:app) and change compileSdkVersion to compileSdk

android {
    compileSdk 33
    defaultConfig {
        applicationId "com.bigknol.example"
        minSdkVersion 26
        targetSdkVersion 33
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    
}

5. R8 Tool / base.jar

Message:

com.android.tools.r8.ResourceException: com.android.tools.r8.internal.Tb: I/O exception while reading (app/build/intermediates/merged_java_res/release/base.jar)

This indicates that there is a resource-related exception while using the R8 tool.

I/O exception while reading (app/build/intermediates/merged_java_res/release/base.jar): This part of the error message specifies that there was an input/output (I/O) exception while attempting to read a JAR file named base.jar in the release variant of your app’s merged Java resources.

Possible fixes

1. Ensure that your project’s dependencies and build configuration are set up correctly. Sometimes, problems with dependencies or build.gradle configurations can lead to issues like this.

2. If the JAR file is corrupted or causing the issue, you may need to examine the specific content in that JAR file, and if possible, replace it with a non-corrupted version.

3. Replacement of whenTaskAdded

tasks.whenTaskAdded { task ->
    println(task.name)
    if (task.name.contains("assembleDebug")) {
        task.dependsOn checkDebug
    }
    if (task.name.contains("assembleRelease")) {
        task.dependsOn checkRelease
    }
}

Replaced by tasks.configureEach

tasks.configureEach { task ->
    println(task.name)
    if (task.name.contains("assembleDebug")) {
        task.dependsOn checkDebug
    }
    if (task.name.contains("assembleRelease")) {
        task.dependsOn checkRelease
    }
}

6. Namespace not specified

Message:

Namespace not specified. Specify a namespace in the module’s build file. See https://d.android.com/r/tools/upgrade-assistant/set-namespace for information about setting the namespace.

If you’ve specified the package attribute in the source AndroidManifest.xml, you can use the AGP Upgrade Assistant to migrate to the namespace value in the build file. Refer to https://d.android.com/r/tools/upgrade-assistant/agp-upgrade-assistant for general information about using the AGP Upgrade Assistant.

Fix

Step 1: Open build.gradle(app)

Step 2: Add a namespace statement.

namespace [‘app package name’]

 android {

namespace 'com.bigknol.demo.app'


}

7. No matching variant of com.android.tools.build:gradle

Message:

“No matching variant of com.android.tools.build:gradle:8.1.0 was found. The consumer was configured to find a library for use during runtime, compatible with Java 8, packaged as a jar, and its dependencies declared externally, as well as attribute ‘org.gradle.plugin.api-version’ with value ‘8.0’ but:”

The message suggests that your project is trying to use version 8.1.0 of the Android Gradle plugin but is unable to find a compatible variant of it. Variants can include different configurations for specific use cases, and it appears that a suitable variant is missing or not available.

Fix

Step 1: Change the Gradle (JDK) to any compatible version (eg: use jbr-17 instead of Java 8)

Step 2: Open Android Studio > Preference (Mac) / Settings (Windows) > Build, Execution, Deployment > Build Tools > Gradle

android errors : fix gradle No matching variant of com.android.tools.build:gradle

Happy debugging!

You may also like...