1

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

我一直在关注本教程:

但是,我遇到了很多困难。以下是我一直在采取的步骤以及我遇到的问题。

  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')在它的依赖项下添加。

然后我遇到了问题。当我尝试同步项目时,我收到一个构建错误消息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')
}

或者,是否需要将有关我的 buildTypes 的信息移动到installedgradle 文件中?

4

0 回答 0