[英]Android Gradle Plugin 3.0 Build Error
遇到遷移到Android gradle插件3.0的問題 。
項目根目錄下的build.gradle文件
buildscript {
repositories {
jcenter()
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.1'
}
}
Android 應用程序模塊build.gradle
buildscript {
repositories {
maven { url 'https://maven.fabric.io/public' }
mavenCentral()
}
dependencies {
classpath 'io.fabric.tools:gradle:1.+'
classpath testDependencies.spoon
}
}
repositories {
maven { url 'https://maven.fabric.io/public' }
}
apply plugin: 'com.android.application'
apply plugin: 'io.fabric'
spoon {
debug = true
grantAllPermissions = true
shard = true
}
android {
compileSdkVersion 25
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
試圖編譯一個項目。 我收到編譯錯誤。
但是,一旦retrolambda再次被添加回來,那么該項目將成功編譯和構建。 閱讀“已知問題”部分,但沒有找到解決方法。 我希望有人能夠體驗到這一點,並能提供幫助
如果在更新插件后確實遇到構建錯誤,只需在此頁面中搜索錯誤輸出或導航到相關主題,然后按照說明解決問題。
例如,請考慮主項目的build.gradle文件中包含的以下類路徑依賴項:
buildscript {
...
dependencies {
classpath "com.android.tools.build:gradle:3.0.1"
classpath "me.tatarka:gradle-retrolambda:3.7.0"
}
}
現在考慮復合構建中包含的另一個項目的以下build.gradle文件:
buildscript {
dependencies {
// Note that the order of plugins differs from that
// of the main project's build.gradle file. This results
// in a build error because Gradle registers this as a
// different classloader.
classpath "me.tatarka:gradle-retrolambda:3.7.0"
classpath "com.android.tools.build:gradle:3.0.1"
}
}
你有沒有訂
apply plugin: 'me.tatarka.retrolambda'
將me.tatarka:gradle-retrolambda
插件添加為build.gradle
文件的依賴build.gradle
。
buildscript {
repositories {
google()
mavenCentral()
}
dependencies {
classpath "com.android.tools.build:gradle:3.0.1"
classpath 'me.tatarka:gradle-retrolambda:3.7.0'
}
}
// Required because retrolambda is on maven central
repositories {
mavenCentral()
}
然后將源和目標兼容性添加到Java 8
並在app/build.gradle
文件中app/build.gradle
新插件。
apply plugin: 'com.android.application'
apply plugin: 'me.tatarka.retrolambda' // Add this
android {
compileSdkVersion 27
buildToolsVersion "27.0.0"
defaultConfig {
applicationId " "
minSdkVersion //
targetSdkVersion //
versionCode //
versionName //
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
FYI
如果您使用Gradle 3.0.0 or higher
版本的Android插件,您的項目將自動使用插件指定的默認版本的構建工具。 要使用不同版本的構建工具, buildToolsVersion
在模塊的 build.gradle
使用buildToolsVersion
指定它,如下所示:
/**
* buildToolsVersion specifies the version of the SDK build tools, command-line
* utilities, and compiler that Gradle should use to build your app. You need to
* download the build tools using the SDK Manager.
*
* If you're using Android plugin 3.0.0 or higher, this property is optional—
* the plugin uses a recommended version of the build tools by default.
*/
android {
compileSdkVersion 26
buildToolsVersion "26.0.2"
}
您應該upgrade
buildToolsVersion
版本。
android {
compileSdkVersion 27
buildToolsVersion "27.0.0"
然后Clean-Rebuild-Restart-Run
。
讀
確保您的BuildToolsVersion已達26
新的android studio 3.0經過必要的最小buildToolsVersion 26.0.0更新此版本的應用內模塊gradle。
android {
compileSdkVersion 25
buildToolsVersion "26.0.3"
}
如果您看到buildtool not found錯誤,則需要安裝此構建工具。
確保這些行在App(模塊)級別gradle文件中
buildToolsVersion
app Configuration的defaultConfig
android {
compileSdkVersion 25
buildToolsVersion "25.0.2"
defaultConfig {
applicationId "com.example.app"
minSdkVersion 16
targetSdkVersion 25
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
vectorDrawables.useSupportLibrary = true
multiDexEnabled true
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.