无法获得未知的财产&application;应用变量'对于com.android.build.gradle.FeatureExtension类型的对象

时间:2018-04-08 14:11:29

标签: android android-gradle android-instant-apps android-module

我正在尝试更新我的应用程序模块,以便将即时应用模块添加到我当前的应用程序中。

我一直在关注本教程:

然而,我遇到了很多困难。以下是我采取的步骤以及我遇到过的问题。

  1. 将gradle构建工具从 2.3.3升级到3.0.1 。应用程序构建并正常运行

  2. 我尝试将当前模块转换为功能模块

    • apply plugin: 'com.android.application'更改为apply plugin: 'com.android.feature'
    • 删除applicationId 'com.example.myapp.app'
    • minifyEnabled已设置为false
    • 将其标记为baseFeature
  3. 我制作了一个新的应用程序模块,并将其命名为已安装。 MinSdk 16,我在其依赖项下添加了compile project(':app')

  4. 然后我遇到了问题。当我尝试同步项目时,我收到一个构建错误,说Could not get unknown property 'applicationVariants' for object of type com.android.build.gradle.FeatureExtension.,发生在我新转换的功能模块中。我确实有一些代码改变了applicationVariant,

    android.applicationVariants.all { variant ->...但是,当我发表评论时,错误仍然存​​在。但是,这一次,它没有显示打开的文件链接。我想知道这是来自我的另一个依赖项,还是来自我的另一个自定义gradle操作。 (注意,我不会在任何其他时间引用android.applicationVariants。)

    有没有人想过这个错误可能来自哪里?是否存在某些不属于功能模块的依赖项?或者其他人有不同的方式让即时应用程序工作?非常感谢任何建议。

    这是安装的build.gradle文件:

    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'
    }
    

    以下是我的功能app模块的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')
    }
    

    或者,是否需要将有关我的buildType的信息移到installed的gradle文件中?

0 个答案:

没有答案