1

I'm attempting to update my application's modules in order to add an instant app module to my current application.

I've been following along with this tutorial:

However I've been running into quite a few struggles. Here are the steps I've been taking and the issues i've been encountering.

  1. Upgraded the gradle build tools from 2.3.3 to 3.0.1. App builds and runs as normal

  2. I try and convert the current module to a feature module

    • Change apply plugin: 'com.android.application' to apply plugin: 'com.android.feature'
    • Remove applicationId 'com.example.myapp.app'
    • minifyEnabled already set to false
    • tagged it as the baseFeature
  3. I make a new application module and name it installed. MinSdk 16, and I add compile project(':app') under it's dependencies.

I then run into issues. When I try and sync the project, I get a build error saying Could not get unknown property 'applicationVariants' for object of type com.android.build.gradle.FeatureExtension., occurring in my newly converted feature module. I did have some code that altered the the applicationVariant,

android.applicationVariants.all { variant ->..., however, event when I comment it out, the error still occurs. However, this time, it doesn't show an open file link. I'm wondering if this is coming from another one of my dependencies, or if it is coming from another one of my custom gradle operations. (Note, i do not reference android.applicationVariants at any other time).

Does anyone have any thoughts as to where this error could be coming from? Are there certain dependencies that do not belong in feature modules? Or did anyone else have a different way to get instant apps working? Any suggestions are greatly appreciated.

here is the installed build.gradle file:

apply plugin: 'com.android.application'

ext.versionMajor = v
ext.versionMinor = v
ext.versionPatch = getPatchNumber()

android {
  compileSdkVersion 27

  defaultConfig {
    applicationId "com.example.myapp.installed"
    minSdkVersion 16
    targetSdkVersion 27

    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    versionCode generateVersionCode()
    versionName generateVersionName()
  }

  buildTypes {
    release {
      minifyEnabled false
      proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
  }

}

dependencies {
  compile project(':app')
  compile fileTree(dir: 'libs', include: ['*.jar'])

  compile "com.android.support:appcompat-v7:$supportVersion"
  testCompile 'junit:junit:4.12'
  androidTestCompile 'com.android.support.test:runner:1.0.1'
  androidTestCompile 'com.android.support.test.espresso:espresso-core:3.0.1'
}

Here is my feature app module's build.gradle:

buildscript {
  repositories {
    jcenter()
    maven { url "https://oss.sonatype.org/content/repositories/snapshots" }
    maven { url 'https://maven.fabric.io/public' }
    maven { url "https://jitpack.io" }
    maven { url "https://plugins.gradle.org/m2/" }
    google()
  }

  dependencies {
    classpath 'com.android.tools.build:gradle:3.0.1'
    classpath 'io.fabric.tools:gradle:1.25.1'
    classpath 'com.google.gms:google-services:3.1.1'
    classpath 'com.jakewharton:butterknife-gradle-plugin:9.0.0-SNAPSHOT'
    classpath "gradle.plugin.me.tatarka:gradle-retrolambda:3.6.1"
    classpath 'org.ajoberstar:gradle-git:1.7.2',
    classpath 'com.dicedmelon.gradle:jacoco-android:0.1.2'
  }
}

plugins {
  ...
}

apply plugin: 'com.android.feature'
apply plugin: 'io.fabric'
apply plugin: "me.tatarka.retrolambda"
apply plugin: 'org.ajoberstar.grgit'
apply plugin: 'jacoco'
apply plugin: 'com.onesignal.androidsdk.onesignal-gradle-plugin'

repositories {
  google()
  jcenter()
  mavenCentral()
  maven { url "https://oss.sonatype.org/content/repositories/snapshots" }
  maven { url 'https://maven.fabric.io/public' }
  maven { url "https://jitpack.io" }
  maven { url "https://clojars.org/repo/" }
}

android {

  baseFeature = true

  ...linting stuff

  compileSdkVersion 27
  buildToolsVersion "27.0.3"

  testBuildType "debug"

  defaultConfig {
    minSdkVersion 16
    targetSdkVersion 27
    multiDexEnabled = true
    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
//    versionCode generateVersionCode() // moved to the new installed module
//    versionName generateVersionName() // moved to the new installed module

    javaCompileOptions {
      annotationProcessorOptions {
        arguments = ["room.schemaLocation": "$projectDir/schemas".toString()]
      }
    }
  }

  packagingOptions {
    exclude 'META-INF/LICENSE.txt'
    exclude 'META-INF/NOTICE.txt'
    exclude 'META-INF/services/javax.annotation.processing.Processor'
    exclude 'LICENSE.txt'
  }

  signingConfigs {
    debug {
      storeFile file("...")
    }
    release {
      ...
    }
  }

  buildTypes {
    release {
      minifyEnabled false
      ...
    }
    staging {
      debuggable true
      minifyEnabled false
      ...
    }
    debug {
      ...
    }
  }

  compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
  }
}

dependencies {
  // dagger
  compile "com.google.dagger:dagger:$daggerVersion"...

  // retrofit
  compile 'com.squareup.retrofit2:retrofit:2.3.0'...

  // support
  compile "com.android.support:transition:$supportVersion"
  ...

  // gson
  compile 'com.google.code.gson:gson:2.8.0'

  // timber
  compile 'com.jakewharton.timber:timber:4.5.1'

  // play services
  compile "com.google.android.gms:play-services-analytics:$playServicesVersion"
  compile "com.google.android.gms:play-services-gcm:$playServicesVersion"

  // butterknife
  compile "com.jakewharton:butterknife:$butterknifeVersion"
  annotationProcessor "com.jakewharton:butterknife-compiler:$butterknifeVersion"

  // room
  compile 'android.arch.persistence.room:runtime:1.0.0'
  annotationProcessor 'android.arch.persistence.room:compiler:1.0.0'

  compile "com.android.support:multidex:$multidexVersion"
  androidTestCompile "com.android.support:multidex:$multidexVersion"

  compile 'com.jpardogo.materialtabstrip:library:1.1.0'
  compile 'net.danlew:android.joda:2.9.5.1'

  //auto value
//  provided 'frankiesardo:auto-parcel:1.0.3'
//  compile "com.google.auto.value:auto-value:1.5"
  annotationProcessor 'com.google.auto.value:auto-value:1.4'
  provided 'com.jakewharton.auto.value:auto-value-annotations:1.4'
  annotationProcessor 'com.ryanharter.auto.value:auto-value-parcel:0.2.6'

  // Testing-only dependencies
  // Force usage of support annotations in the test app, since it is internally used by the runner module.
  androidTestCompile "com.android.support:support-annotations:$supportVersion"
  ...

  androidTestCompile 'com.google.code.findbugs:jsr305:3.0.1'
  androidTestCompile 'org.mockito:mockito-android:2.7.22'
  ...

  application project(':installed')
}

Or, does information about my buildTypes need to be moved into installed's gradle file?

Prags
  • 2,457
  • 2
  • 21
  • 38
hermt2
  • 844
  • 3
  • 14
  • 33
  • Can you file a bug to Google, then link to it back in here? It would be helpful for all, thanks! https://issuetracker.google.com/issues/new?component=316045&template=1018787 – Prags Apr 11 '18 at 08:10
  • `applicationVariants` doesn't belong in the feature module, it goes to the application module. (and it's recommended to transition to implementaion/api instead of compile now https://developer.android.com/studio/build/gradle-plugin-3-0-0-migration.html#new_configurations) – TWL Apr 11 '18 at 20:26
  • try the solution from https://stackoverflow.com/questions/45101309/could-not-get-unknown-property-for-applicationvariants-for-buildtype-decorated – João Carlos Oct 16 '20 at 20:42

0 Answers0