Android Gradle:无法编译

Android Gradle:无法编译,android,Android,我是android gradle的新手。我在汇编方面有问题。我有两个独立的项目,一个是common_lib(Java lib),一个是TestApp(Android)。以下是项目结构: 公共图书馆: 只有一个名为Hello.java的简单类 public class Hello { } build.gardle: apply plugin: 'java' dependencies { compile fileTree(dir: 'libs', include: ['*.jar'])

我是android gradle的新手。我在汇编方面有问题。我有两个独立的项目,一个是common_lib(Java lib),一个是TestApp(Android)。以下是项目结构:

公共图书馆: 只有一个名为Hello.java的简单类

public class Hello {
}
build.gardle:

apply plugin: 'java'

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
}
buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:1.1.3'
    }
}
apply plugin: 'com.android.application'

repositories {
    jcenter()
}

android {
    compileSdkVersion 15
    buildToolsVersion "22.0.1"

    defaultConfig {
        applicationId "com.test.app"
        minSdkVersion 15
        targetSdkVersion 15
        versionCode 1
        versionName "1.0"
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_6
        targetCompatibility JavaVersion.VERSION_1_6
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
}
我编译了common_lib,编译成功,然后我将common_lib.jar复制到TestApp\libs项目

TestApp:

AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.test.app" >

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name=".MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>
build.gardle:

apply plugin: 'java'

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
}
buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:1.1.3'
    }
}
apply plugin: 'com.android.application'

repositories {
    jcenter()
}

android {
    compileSdkVersion 15
    buildToolsVersion "22.0.1"

    defaultConfig {
        applicationId "com.test.app"
        minSdkVersion 15
        targetSdkVersion 15
        versionCode 1
        versionName "1.0"
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_6
        targetCompatibility JavaVersion.VERSION_1_6
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
}
我的问题是,在编译TestApp项目时,出现了以下错误:

错误:梯度:任务“:app:preDexRelease”的执行失败

com.android.ide.common.process.ProcessException:org.gradle.process.internal.ExecException:process'命令 “C:\Program Files\Java\jdk1.8.0\u 25\bin\Java.exe”已完成 非零出口值1


如果我从libs文件夹中删除common_lib.jar,我就可以编译该项目。问题出在哪里?

删除行
编译文件树(包括:['*.jar'],dir:'libs')
,然后尝试清洁构建


只需删除所有库jar文件

删除行
编译文件树(包括:['*.jar'],dir:'libs')
,然后尝试清洁构建



只需删除任何库jar文件

我想使用common_lib.jar,如果我删除compile fileTree(包括:['*.jar'],dir:'libs'),我就不能在TestApp项目中使用它。这也可能是因为重复的libs不存在重复的libs,只有2个简单的项目,在我复制文件夹中的common_lib.jar之前,libs文件夹是空的。您的java版本是什么?立即工作!问题是如果common_lib.jar是1.7 java版本,那么android SDK需要更改为1.7 java SDK来构建。我想使用common_lib.jar,如果我删除compile fileTree(包括:['*.jar'],dir:'libs'),我就不能在TestApp项目中使用它。这也可能是因为重复的libs不存在,只有2个简单的项目,在我复制文件夹中的common_lib.jar之前,libs文件夹是空的。您的java版本是什么?立即工作!问题是,如果common_lib.jar是1.7Java版本,那么android SDK需要更改为1.7Java SDK才能构建。错误信息会更多。检查这一行的上方。信息:渐变:执行任务:[:app:assembleDebug]信息:由于项目配置/依赖项更改,模块“app”已完全重建信息:2015年6月21日下午2:26-编译完成,10秒内出现1个错误和0个警告51ms错误:渐变:任务执行失败:app:preDexDebug'>com.android.ide.common.process.ProcessException:org.gradle.process.internal.ExecException:process'command'C:\Program Files\Java\jdk1.8.0_25\bin\Java.exe''以非零退出值1结束jar文件是如何生成的?里面有android库吗?这可能是由于多索引问题。只是一个简单的项目,没有任何jar引用,只有一个类Hello.java。你可以试试。只需创建一个java项目,一个android项目,并将编译好的jar复制到android项目中,您就会遇到我的问题。错误的信息会更多。检查这一行的上方。信息:渐变:执行任务:[:app:assembleDebug]信息:由于项目配置/依赖项更改,模块“app”已完全重建信息:2015年6月21日下午2:26-编译完成,10秒内出现1个错误和0个警告51ms错误:渐变:任务执行失败:app:preDexDebug'>com.android.ide.common.process.ProcessException:org.gradle.process.internal.ExecException:process'command'C:\Program Files\Java\jdk1.8.0_25\bin\Java.exe''以非零退出值1结束jar文件是如何生成的?里面有android库吗?这可能是由于多索引问题。只是一个简单的项目,没有任何jar引用,只有一个类Hello.java。你可以试试。只需创建一个java项目,一个android项目,并将编译好的jar复制到android项目,那么您就会遇到我的问题。