Android Gradle:无法编译

时间:2015-06-21 13:59:25

标签: android

我是android gradle中的新手。我在编译时遇到问题。我有2个独立的项目,一个是common_lib(Java lib),一个是TestApp(Android)。以下是项目结构:

common_lib: 只有一个名为Hello.java的简单类

public class Hello {
}

build.gardle:

apply plugin: 'java'

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
}

我编译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>

MainActivity:

public class MainActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }
}

build.gardle:

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项目时,我收到以下错误:

  

错误:Gradle:任务执行失败&#39;:app:preDexRelease&#39;。

     
    

com.android.ide.common.process.ProcessException:org.gradle.process.internal.ExecException:Process&#39;命令     &#39; C:\ Program Files \ Java \ jdk1.8.0_25 \ bin \ java.exe&#39;&#39;完成了     非零退出值1

  

如果从libs文件夹中删除common_lib.jar,我可以编译该项目。有什么问题?

1 个答案:

答案 0 :(得分:0)

删除行compile fileTree(include: ['*.jar'], dir: 'libs')并尝试清理构建

删除所有库jar文件