2
  • In application module, we can use applicationVariants.
  • In feature module, we can use featureVariants.
  • In library module, we can use libraryVariatns.

Where is instantAppVariants???

UPDATE: Back story: I want to generate BuildConfig and versionCode/String differently for application and instant app, but it did not work, so I tried to use variants to see if that helps, but then I find out there is no instantAppVariant for me to loop thr. the variants and update the data.

Brian Chu
  • 113
  • 9
  • What do you want to achieve from that? I don't know if it exists, but since the instant app module just collects APKs built from other feature modules in one archive, not much can be changed at that level. – Hassan Ibraheem Jan 02 '19 at 08:46
  • see https://stackoverflow.com/questions/47425735/android-can-you-add-activities-to-the-instant-app-module – TWL Jan 02 '19 at 18:04
  • I enhance the question with what I mean to archive. – Brian Chu Jan 02 '19 at 23:04
  • Thanks. That's helpful. If you don't want to use flavors, and don't mind running your build twice (once for instant app, and once for full app), you may consider moving these variables into environment variables that you can set per each build. One other thing to try, is to set version code and name for all feature modules, and a different one for app module. The full app APK will use the ones from app module, while instant app APKs use the other. (I haven't tried that, but it should work, specially if you keep them the same in all feature modules) – Hassan Ibraheem Jan 13 '19 at 15:56

2 Answers2

1

I want to generate BuildConfig and versionCode/String differently for application and instant app

Use productFlavors , example:

application module:

productFlavors {
    instant {
        dimension rootProject.flavorDim
        minSdkVersion rootProject.minSdkInstant
        versionCode rootProject.versionCodeInstant
        versionName rootProject.versionNameInstant
    }
    installed {
        dimension rootProject.flavorDim
        minSdkVersion rootProject.minSdk
        versionCode rootProject.versionCode
        versionName rootProject.versionName
    }
}

feature module(s):

productFlavors {
    instant {
        dimension rootProject.flavorDim
        minSdkVersion rootProject.minSdkInstant
    }
    installed {
        dimension rootProject.flavorDim
        minSdkVersion rootProject.minSdk
    }
}

Now your:

  • installed app has minSdk / versionCode/Name
  • and instant app has minSdkInstant / versionCodeInstant/NameInstant

You can play around with this for other attributes, but here are some related posts:

Also a doc on Configure build variants

But if this isn't what you're looking for, then you're gonna have to give a working example of your usage.

TWL
  • 6,228
  • 29
  • 65
0

Based from this site,

When an app makes use of Instant Apps, that app is divided into one or more feature modules, each of which is contained within a separate feature APK file. Each feature consists of a specific area of functionality within the app, typically involving one or more Activity instances. The individual feature APKs are then bundled into an instant app APK which is then uploaded to the Google Play Developer Console.

This means that both the app and instant app modules serve as containers for the feature modules that make up the app. An app must contain at least one feature module and may also contain additional modules for other features.

The build.gradle file for the instant app module, on the other hand, will use the com.android.instantapp plugin to build separate feature APK files for the features referenced in the dependencies section. Note that feature dependencies are referenced using implementation project() declarations:

apply plugin: 'com.android.instantapp'

dependencies {
    implementation project(':myappbase')
    implementation project(':myappfeature')
}
Jessica Rodriguez
  • 2,899
  • 1
  • 12
  • 27