Java app:TransformClasses with DexForDeBug及多个模块
我试图创建一个依赖于java库模块中的java代码的android应用程序,但是每当我尝试使用该java库中的任何对象时,我总是得到以下结果 任务“:app:transformClassesWithDexForDebug”的执行失败 com.android.build.api.transform.TransformException:com.android.ide.common.process.ProcessException:org.gradle.process.internal.ExecException:process'command'C:\Program Files\Java\jdk1.8.0_121\bin\Java.exe''以非零退出值1结束 我已经看了下面的内容,并且尝试了几乎所有的建议,但仍然无法构建。我的java库确实使用了android使用的json库,我收到了一些警告,但它说它将被忽略 这是我的身材,格雷德尔Java app:TransformClasses with DexForDeBug及多个模块,java,android,Java,Android,我试图创建一个依赖于java库模块中的java代码的android应用程序,但是每当我尝试使用该java库中的任何对象时,我总是得到以下结果 任务“:app:transformClassesWithDexForDebug”的执行失败 com.android.build.api.transform.TransformException:com.android.ide.common.process.ProcessException:org.gradle.process.internal.ExecEx
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion "25.0.2"
defaultConfig {
applicationId "pwils33.familymap"
minSdkVersion 23
targetSdkVersion 25
versionCode 1
versionName "1.0"
multiDexEnabled true
}
buildTypes {
debug {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
dexOptions {
javaMaxHeapSize "4g"
preDexLibraries false
incremental true
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
testCompile 'junit:junit:4.12'
compile project(':shared')
compile 'com.android.support:appcompat-v7:25.3.0'
compile 'com.android.support:support-v4:25.3.0'
compile 'com.android.support:multidex:1.0.1'
}
我正在将该模块用于我构建的另一个java应用程序,因此无法将其转换为android库。任何帮助都将不胜感激
编辑我也尝试过让我的应用程序成为一个多索引应用程序,这也不起作用,这是我的应用程序清单
<?xml version="1.0" encoding="utf-8"?>
<manifest package="pwils33.familymap"
xmlns:android="http://schemas.android.com/apk/res/android">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme"
android:name="android.support.multidex.MultiDexApplication">
<activity android:name=".activities.MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
</application>
</manifest>
尝试以下代码来解决您的问题:
android {
defaultConfig {
minSdkVersion 15
targetSdkVersion 25
multiDexEnabled true
}
}
dependencies {
compile 'com.android.support:multidex:1.0.1'
}
在应用程序的模块
build.gradle
文件中包括multidex
库:
compile 'com.android.support:multidex:1.0.1'
然后在defaultConfig
部分中通过添加以下内容启用多重索引:
multiDexEnabled true
如果您不重写
应用程序
,请编辑清单的,我终于找到了答案。事实证明,multi-dex库不支持1.8,因为我的计算机上有java 8,当它从我的java模块中找到编译后的代码时,它正在破坏它。我在java模块的build.gradle中添加了以下几行代码,以最终使其工作
sourceCompatibility = 1.7
targetCompatibility = 1.7
dependencies {
...
}
我试过了,也没用,我会更新帖子,这怎么适用于一个有多个模块的项目?
public class AndroidApplication extends MultiDexApplication { ... }
MultiDex.install(this);
sourceCompatibility = 1.7
targetCompatibility = 1.7
dependencies {
...
}