3

I am trying to add some functionality to an existing application. The app's build.gradle contains several productFlavors and a couple of buildTypes. I have tried to replicate that as best I can in my dynamic-feature module, but I cannot seem to get it to install properly from Android Studio.

I followed the example from: https://github.com/googlearchive/android-dynamic-features to set up my feature module, so my project is structured like

app
features/module/build.gradle
build.gradle

I added a buildType and flavor to the app build.gradle

defaultConfig {
    minSdkVersion 24
    targetSdkVersion 28
 }
dynamicFeatures = [":features:module"]
buildTypes{
    myBuildType {
        debuggable true
        multiDexEnabled true
    }
}

flavorDimensions "blah"
productFlavors{
        arm64 {
            ndk {
                abiFilters "arm64-v8a"
            }
            ext {
                abiVersionCode = 5
            }
            matchingFallbacks = ['defaultFlavor']
        }
}

and in the module build.gradle, I have attempted to match that with:

defaultConfig {
    minSdkVersion 24
    targetSdkVersion 28
    }
buildTypes {

    dynamic {
        multiDexEnabled true
        debuggable true
    }
}


flavorDimensions "blah"
productFlavors {
    arm64 {
        ext {
            abiVersionCode = 5
        }
    }
dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation project(':app')
}

In my Run->Edit Configuration screen, I have put a checkbox next to both the base app and the module under the dynamic features to deploy section. I am trying to test this on a Nokia 6, with Android 9.0 running on it. The only output I get from the build is:

01/12 22:39:25: Launching 'app' on HMD Global TA-1025.
Installation did not succeed.
The application could not be installed: INSTALL_FAILED_INVALID_APK
The APKs are invalid.
Derek
  • 11,715
  • 32
  • 127
  • 228
  • Note to self- Remember to check the android studio log in the future, for more information. – Derek Jul 11 '20 at 01:24

5 Answers5

3

It just happened to me. Turns out I was setting different flavors for different modules.
Try selecting the same variants under View > Tool Windows > Build Variants.

Cesar Castro
  • 1,892
  • 1
  • 13
  • 19
2

Please check those things

1) making sure that the AndroidManifest.xml package name was the same as the 
   build.grade applicationId
2) check package name in your Androidmanifest.xml see whether started with one empty space character. like " com.example.test" instead of "com.example.test" and make sure contain at least one dot in your package name like "com.exampletest" instead of "comexampletest" https://code.google.com/p/android/issues/detail?id=55841
3)"Build" > "Clean Project"
4)reboot the android system
isuru
  • 535
  • 1
  • 9
  • 25
  • Yes, this can be the cause. – Parth Patel Jan 13 '20 at 05:41
  • Am I reading this right - are you saying the dynamic feature manifest has to have the same package name as the build.gradle applicationId, and the same applies to the base App? This project does have a script that does some modification of the base app's AndroidManifest.xml I will have to look and see if it is doing something weird, but the base app APK installs fine from the command line or Android Studio. I get the same error trying to deploy the dynamic feature APK without the base App, and have not been able to figured out how to "adb install" two APKs at once – Derek Jan 13 '20 at 20:44
  • I believe this may have been the problem. I had a DSL that was modifying the manifest name, which I removed. – Derek Jul 11 '20 at 01:24
2

Try Edit Configurations > Installations Options > Deploy APK from app bundle

Chetan
  • 226
  • 3
  • 12
0

I found a solution that resolved my problem. Make sure your libraries and class paths are up to date. I had a class for firebase plugins that were out of date. This problem occurred when using the new graddle. 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
-2

I had same problem when I used Flavors (Build variants) in my app. The solution for me was select another build variant in Build Variants tab (for example, release instead of debug flavor), then select the correct build variant, and then Clean, Rebuild.

I found this solution here: https://stackoverflow.com/a/65630971/6543967

Ruslan
  • 87
  • 1
  • 10