我添加了需要的 jar,
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
需要jack支持java8.
根据最新的 kotlin 插件,Error:Kotlin Gradle plugin does not support the deprecated Jack toolchain。 禁用 Jack 或恢复到 Kotlin Gradle 插件版本 1.1.1。
目前无法用 java7 重新创建 jar。并且需要使用已弃用 Jack 工具链的最新版本的 kotlin。
我在 app.gradle 中检查了所有可能的方式。
根据 this 无法通过 studio 3.0 预览版解决此问题.
项目级gradle文件,
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext.kotlin_version = '1.1.3'
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.3'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
应用级gradle文件,
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
android {
compileSdkVersion 25
buildToolsVersion "25.0.3"
defaultConfig {
applicationId "com.example.root.trial"
minSdkVersion 15
targetSdkVersion 25
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
testCompile 'junit:junit:4.12'
compile files('libs/bel-1.0.jar')
compile "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
}
repositories {
mavenCentral()
}
最佳答案
您还没有更新 build.gradle(:project) 中的 gradle 插件。
用以下内容替换您的项目级 gradle 文件:
buildscript {
ext.kotlin_version = '1.1.3-2'
repositories {
maven { url 'https://maven.google.com' }
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.0-alpha9'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
maven { url 'https://maven.google.com' }
jcenter()
}
}
希望对你有帮助。
关于java - Android - 无法添加使用 kotlin 在 java8 中创建的 jar,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45452482/