Android 启用 jack 的 Studio 构建错误
Android Studio build errors with jack enabled
所以我最近将 Android Studio 默认值 JDK 更改为 Java 8,这样我就可以使用 Lambda 表达式了。我必须启用 Jack 才能让 gradle 构建,但现在当我尝试重建我的应用程序时,我收到大约 3 个不同的错误,这些错误似乎来自 Jack。我似乎找不到任何这些问题的根源,并希望继续使用 J8 进行构建。非常感谢任何对此的见解或帮助。以下是我在构建过程中遇到的错误:
1)
Error:Library reading phase: Type javax.inject.Named from file
'C:\Users\nicholas\AndroidStudioProjects\BaseIntegrations\app\build\intermediates\jill\debug\packaged\javax.inject-2.4.0-b10-e2682135301b663484690f1d3a4a523bcea2a732.jar'
has already been imported from file
'C:\Users\nicholas\AndroidStudioProjects\BaseIntegrations\app\build\intermediates\jill\debug\packaged\javax.inject-1-4a242883e90a864db3b80da68e11a844f842d2df.jar',
type 'javax.inject.Named' (see property 'jack.import.type.policy' for
type collision policy)
2)
Error:com.android.jack.JackAbortException: Library reading phase: Type
javax.inject.Named from file
'C:\Users\nicholas\AndroidStudioProjects\BaseIntegrations\app\build\intermediates\jill\debug\packaged\javax.inject-2.4.0-b10-e2682135301b663484690f1d3a4a523bcea2a732.jar'
has already been imported from file
'C:\Users\nicholas\AndroidStudioProjects\BaseIntegrations\app\build\intermediates\jill\debug\packaged\javax.inject-1-4a242883e90a864db3b80da68e11a844f842d2df.jar',
type 'javax.inject.Named' (see property 'jack.import.type.policy' for
type collision policy)
3)
Error:com.android.jack.backend.jayce.TypeImportConflictException: Type
javax.inject.Named from file
'C:\Users\nicholas\AndroidStudioProjects\BaseIntegrations\app\build\intermediates\jill\debug\packaged\javax.inject-2.4.0-b10-e2682135301b663484690f1d3a4a523bcea2a732.jar'
has already been imported from file
'C:\Users\nicholas\AndroidStudioProjects\BaseIntegrations\app\build\intermediates\jill\debug\packaged\javax.inject-1-4a242883e90a864db3b80da68e11a844f842d2df.jar',
type 'javax.inject.Named' (see property 'jack.import.type.policy' for
type collision policy)
4)
:app:compileDebugJavaWithJack FAILED
Error:Execution failed for task ':app:compileDebugJavaWithJack'.
java.io.IOException: com.android.jack.api.v01.CompilationException: Library reading phase: Type javax.inject.Named from file 'C:\Users\nicholas\AndroidStudioProjects\BaseIntegrations\app\build\intermediates\jill\debug\packaged\javax.inject-2.4.0-b10-e2682135301b663484690f1d3a4a523bcea2a732.jar' has already been imported from file 'C:\Users\nicholas\AndroidStudioProjects\BaseIntegrations\app\build\intermediates\jill\debug\packaged\javax.inject-1-4a242883e90a864db3b80da68e11a844f842d2df.jar', type 'javax.inject.Named' (see property 'jack.import.type.policy' for type collision policy)
这是应用级别build.gradle:
android {
compileSdkVersion 24
buildToolsVersion "24.0.1"
defaultConfig {
applicationId "com.nicholas.baseintegrations"
minSdkVersion 16
targetSdkVersion 24
versionCode 1
versionName "1.0"
jackOptions {
enabled true
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
useLibrary 'org.apache.http.legacy'
compileOptions {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:24.2.0'
compile 'com.google.android.gms:play-services-gcm:9.4.0'
compile project(path: ':backend', configuration: 'android-endpoints')
compile "com.getbase:basecrm-java:1.4.3"
compile 'com.android.support:recyclerview-v7:24.2.0'
compile 'com.android.support:palette-v7:24.2.0'
compile 'com.android.support:cardview-v7:24.2.0'
compile 'com.android.support:design:24.2.0'
compile group: 'org.slf4j', name: 'slf4j-simple', version: '1.7.21'
compile group: 'org.glassfish.jersey.media', name: 'project', version: '2.23.2', ext: 'pom'
}
非常感谢所有帮助,因为我知道这是一个新事物,但似乎无法找到有关 Jack/J8 构建过程的问题。提前致谢。
我们正在调查此问题,我认为这是由于 Jack 和 javac 的 Android Gradle 插件的不同行为所致。作为解决方法,您可以在 jackOptions
中尝试此操作
additionalParameters = [ "jack.import.type.policy" : "keep-first" ]
但请注意,使用该选项,Jack 将保留它遇到的 class 的第一个定义。
您可以在此处跟踪我们的进度:https://code.google.com/p/android/issues/detail?id=222273
我最终解决了这个构建问题。我的一个依赖项是添加第二个 javax.inject 库,它抛出这些构建错误,说 javax.inject jar 已经从前一个导入。
所以我有 javax.inject-1 和 javax.inject-2.4.0-b10。我最终从我的一个依赖项中排除了 javax.inject 模块,它解决了构建问题并且现在工作正常。
这是我的应用程序的依赖项部分 build.gradle:
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile project(path: ':backend', configuration: 'android-endpoints')
compile group: 'org.slf4j', name: 'slf4j-simple', version: '1.7.21'
compile (group: 'org.glassfish.jersey.media', name: 'project', version: '2.23.2', ext: 'pom')
compile 'com.android.support:appcompat-v7:24.2.1'
compile 'com.google.android.gms:play-services-gcm:9.4.0'
compile ('com.getbase:basecrm-java:1.4.3') {
exclude (group: 'javax.inject', module: 'javax.inject')
}
compile 'com.android.support:recyclerview-v7:24.2.1'
compile 'com.android.support:palette-v7:24.2.1'
compile 'com.android.support:cardview-v7:24.2.1'
compile 'com.android.support:design:24.2.1'
}
并且您可以在basecrm 依赖项中看到组排除。因此,如果其他人遇到此问题,请注意来自某些依赖项导入的重复外部库。
我遇到了同样的问题,然后我在这两个jar中找到了相同的包,但是它们不是同一个版本。
所以修改为他们有相同的版本。
所以我最近将 Android Studio 默认值 JDK 更改为 Java 8,这样我就可以使用 Lambda 表达式了。我必须启用 Jack 才能让 gradle 构建,但现在当我尝试重建我的应用程序时,我收到大约 3 个不同的错误,这些错误似乎来自 Jack。我似乎找不到任何这些问题的根源,并希望继续使用 J8 进行构建。非常感谢任何对此的见解或帮助。以下是我在构建过程中遇到的错误:
1)
Error:Library reading phase: Type javax.inject.Named from file 'C:\Users\nicholas\AndroidStudioProjects\BaseIntegrations\app\build\intermediates\jill\debug\packaged\javax.inject-2.4.0-b10-e2682135301b663484690f1d3a4a523bcea2a732.jar' has already been imported from file 'C:\Users\nicholas\AndroidStudioProjects\BaseIntegrations\app\build\intermediates\jill\debug\packaged\javax.inject-1-4a242883e90a864db3b80da68e11a844f842d2df.jar', type 'javax.inject.Named' (see property 'jack.import.type.policy' for type collision policy)
2)
Error:com.android.jack.JackAbortException: Library reading phase: Type javax.inject.Named from file 'C:\Users\nicholas\AndroidStudioProjects\BaseIntegrations\app\build\intermediates\jill\debug\packaged\javax.inject-2.4.0-b10-e2682135301b663484690f1d3a4a523bcea2a732.jar' has already been imported from file 'C:\Users\nicholas\AndroidStudioProjects\BaseIntegrations\app\build\intermediates\jill\debug\packaged\javax.inject-1-4a242883e90a864db3b80da68e11a844f842d2df.jar', type 'javax.inject.Named' (see property 'jack.import.type.policy' for type collision policy)
3)
Error:com.android.jack.backend.jayce.TypeImportConflictException: Type javax.inject.Named from file 'C:\Users\nicholas\AndroidStudioProjects\BaseIntegrations\app\build\intermediates\jill\debug\packaged\javax.inject-2.4.0-b10-e2682135301b663484690f1d3a4a523bcea2a732.jar' has already been imported from file 'C:\Users\nicholas\AndroidStudioProjects\BaseIntegrations\app\build\intermediates\jill\debug\packaged\javax.inject-1-4a242883e90a864db3b80da68e11a844f842d2df.jar', type 'javax.inject.Named' (see property 'jack.import.type.policy' for type collision policy)
4)
:app:compileDebugJavaWithJack FAILED Error:Execution failed for task ':app:compileDebugJavaWithJack'. java.io.IOException: com.android.jack.api.v01.CompilationException: Library reading phase: Type javax.inject.Named from file 'C:\Users\nicholas\AndroidStudioProjects\BaseIntegrations\app\build\intermediates\jill\debug\packaged\javax.inject-2.4.0-b10-e2682135301b663484690f1d3a4a523bcea2a732.jar' has already been imported from file 'C:\Users\nicholas\AndroidStudioProjects\BaseIntegrations\app\build\intermediates\jill\debug\packaged\javax.inject-1-4a242883e90a864db3b80da68e11a844f842d2df.jar', type 'javax.inject.Named' (see property 'jack.import.type.policy' for type collision policy)
这是应用级别build.gradle:
android {
compileSdkVersion 24
buildToolsVersion "24.0.1"
defaultConfig {
applicationId "com.nicholas.baseintegrations"
minSdkVersion 16
targetSdkVersion 24
versionCode 1
versionName "1.0"
jackOptions {
enabled true
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
useLibrary 'org.apache.http.legacy'
compileOptions {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:24.2.0'
compile 'com.google.android.gms:play-services-gcm:9.4.0'
compile project(path: ':backend', configuration: 'android-endpoints')
compile "com.getbase:basecrm-java:1.4.3"
compile 'com.android.support:recyclerview-v7:24.2.0'
compile 'com.android.support:palette-v7:24.2.0'
compile 'com.android.support:cardview-v7:24.2.0'
compile 'com.android.support:design:24.2.0'
compile group: 'org.slf4j', name: 'slf4j-simple', version: '1.7.21'
compile group: 'org.glassfish.jersey.media', name: 'project', version: '2.23.2', ext: 'pom'
}
非常感谢所有帮助,因为我知道这是一个新事物,但似乎无法找到有关 Jack/J8 构建过程的问题。提前致谢。
我们正在调查此问题,我认为这是由于 Jack 和 javac 的 Android Gradle 插件的不同行为所致。作为解决方法,您可以在 jackOptions
中尝试此操作additionalParameters = [ "jack.import.type.policy" : "keep-first" ]
但请注意,使用该选项,Jack 将保留它遇到的 class 的第一个定义。
您可以在此处跟踪我们的进度:https://code.google.com/p/android/issues/detail?id=222273
我最终解决了这个构建问题。我的一个依赖项是添加第二个 javax.inject 库,它抛出这些构建错误,说 javax.inject jar 已经从前一个导入。
所以我有 javax.inject-1 和 javax.inject-2.4.0-b10。我最终从我的一个依赖项中排除了 javax.inject 模块,它解决了构建问题并且现在工作正常。
这是我的应用程序的依赖项部分 build.gradle:
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile project(path: ':backend', configuration: 'android-endpoints')
compile group: 'org.slf4j', name: 'slf4j-simple', version: '1.7.21'
compile (group: 'org.glassfish.jersey.media', name: 'project', version: '2.23.2', ext: 'pom')
compile 'com.android.support:appcompat-v7:24.2.1'
compile 'com.google.android.gms:play-services-gcm:9.4.0'
compile ('com.getbase:basecrm-java:1.4.3') {
exclude (group: 'javax.inject', module: 'javax.inject')
}
compile 'com.android.support:recyclerview-v7:24.2.1'
compile 'com.android.support:palette-v7:24.2.1'
compile 'com.android.support:cardview-v7:24.2.1'
compile 'com.android.support:design:24.2.1'
}
并且您可以在basecrm 依赖项中看到组排除。因此,如果其他人遇到此问题,请注意来自某些依赖项导入的重复外部库。
我遇到了同样的问题,然后我在这两个jar中找到了相同的包,但是它们不是同一个版本。 所以修改为他们有相同的版本。