1

I have upgraded my gradle version to 4.0.0 from 3.6.3. Android Studio was able to install the app properly when minifyenabled was true and gradle version was 3.6.3 without any issues. On gradle version 4.0.0 and minifyenabled set to true doesn't even install the application. Here is what I see:

Installation did not succeed.
The application could not be installed: INSTALL_FAILED_INVALID_APK

List of apks:
[0] 'C:\Users\user\Desktop\Projects\Application\app\build\outputs\apk\debug\app-debug.apk'
[1] 'C:\Users\user\Desktop\Projects\Application\module1\build\outputs\apk\debug\module1-debug.apk'
[2] 'C:\Users\user\Desktop\Projects\Application\module2\build\outputs\apk\debug\module2-debug.apk'
[3] 'C:\Users\user\Desktop\Projects\Application\module3\build\outputs\apk\debug\module3-debug.apk'
[4] 'C:\Users\user\Desktop\Projects\Application\module4\build\outputs\apk\debug\module4-debug.apk'
[5] 'C:\Users\user\Desktop\Projects\Application\module5\build\outputs\apk\debug\module5-debug.apk'
The APKs are invalid.

build.gradle file:

android {
    compileSdkVersion androidDependencies.compile_sdk_version
    buildToolsVersion "29.0.3"
    defaultConfig {
        applicationId "com.pills.mydemoapplication"
        minSdkVersion androidDependencies.min_sdk_version
        targetSdkVersion androidDependencies.target_sdk_version
        versionCode 7
        versionName "5.0.2"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }
    kotlinOptions {
        jvmTarget = "1.8"
    }
    buildTypes {
        debug {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
        release {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    buildFeatures{
        dataBinding = true
    }
    dynamicFeatures = [":module1", ":module2", ":module3", ":module4", ":module5"]
}

Project level build.gradle

buildscript {
    ext.kotlin_version = '1.3.72'
    repositories {
        google()
        jcenter()

    }
    dependencies {
        classpath "com.android.tools:r8:1.6.84"
        classpath "com.android.tools.build:gradle:4.0.0"
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        classpath "androidx.navigation:navigation-safe-args-gradle-plugin:2.3.0-beta01"
    }
}
  • I think a project clean (Build -> Clean project) would solve this problem. Cached / compiled files can cause simmilar issues after a version change. – westito May 30 '20 at 06:30
  • I tried cleaning build, invalidate cache and restart, deleting build, .gradle, .idea folders and none of these worked. – Jitendra Reddy May 30 '20 at 12:20
  • It seems a similar issue: https://stackoverflow.com/questions/60790653/how-to-fix-install-failed-invalid-apk-error-in-android-studio – westito May 31 '20 at 13:45
  • Seems similar but unrelated because that doesn't have anything to do with R8. – Jitendra Reddy May 31 '20 at 22:41

2 Answers2

1

Removing the following line from project level build.gradle made it work.

classpath "com.android.tools:r8:1.6.84"

R8 is now bundled with Android Gradle Plugin by default and the version of R8 in AGP is 2.0.74 and I was overriding it with a much older version which broke R8 code shrinking.

0

Make sure all your libraries and classpaths are up to date. I had a classpath for firebase-plugins that was out of date. This problem occurred when using the new gradle. After updating the classpath, everything looks fine.

In my case. I changed this

classpath 'com.google.firebase:firebase-plugins:1.1.0'

to this

classpath 'com.google.firebase:perf-plugin:1.3.1'

Daniel Pína
  • 348
  • 2
  • 7