:app:compileDebugJava使用android studio时失败

时间:2014-02-26 13:39:16

标签: android-ndk android-gradle

在不太明白为什么这不能编译。当我从Eclipse编译并运行相同的源代码时,它编译并运行完美。但是在Android Studio和Gradle下,它只会崩溃。

以下是我的build.gradle

apply plugin: 'android'


def versionMajor = 1
def versionMinor = 0
def versionPatch = 0
def versionBuild = 0

android {
    compileSdkVersion 19
    buildToolsVersion '19.0.1'

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_7
        targetCompatibility JavaVersion.VERSION_1_7
    }

    sourceSets {

        main {
            manifest.srcFile 'src/main/AndroidManifest.xml'
            java.srcDirs = ['src/main/java']
            res.srcDirs = ['src/main/res']
            jni.srcDirs = []
            resources.srcDirs = ['src/main/res']
            jniLibs.srcDirs = ['src/main/libs']
        }
        instrumentTest {
            java.srcDirs = ['src/instrumentTest/java']
        }
    }

    /*
    productFlavors {
        playstore {
            packageName '<package name>'
        }
        amazonappstore {
            packageName '<package name>'
        }
        samsungstore {
            packageName '<package name>'
        }
    }*/
    defaultConfig {
        minSdkVersion 14
        targetSdkVersion 19

        versionCode versionMajor * 10000 + versionMinor * 1000 + versionPatch * 100 + versionBuild
        versionName "${versionMajor}.${versionMinor}.${versionPatch}"

        ndk{
            abiFilter "all"
        }
    }
    buildTypes {

        //build type 3
        release {
            debuggable false
            jniDebugBuild false
            runProguard false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'

            applicationVariants.all { variant ->
                def file = variant.outputFile
                variant.outputFile = new File(file.parent, file.name.replace(".apk", "-" + defaultConfig.versionName + ".apk"))
            }

        }
    }
    //TASKS
    tasks.withType(com.android.build.gradle.tasks.PackageApplication){
        pkgTask -> pkgTask.jniFolders = [new File(projectDir, "libs")]
    }

    task ndkBuild(type:Exec){
        logger.info('ndkBuild Configuration')
        def ndkBuild;
        def ndkBuildingDir = new File("src/main");
        def hasNdk = false;
        logger.info('Project Path: ' +projectDir)
        logger.info('JNI Path: ' +ndkBuildingDir)

        if (System.env.ANDROID_NDK_HOME != null) {
            hasNdk = true;
            ndkBuild = new File(System.env.ANDROID_NDK_HOME, 'ndk-build')
        }
        else
        {
            //if  env variable is not defined then do this
            def Properties localProps = new Properties()
            localProps.load(new FileInputStream(file('../local.properties')))
            if (localProps['ndk.dir'] !=null)
            {
                hasNdk = true;
                ndkBuild = new File(localProps['ndk.dir'], 'ndk-build')
            }
        }

        commandLine ndkBuild, "--directory", ndkBuildingDir


        doFirst {
            if (!hasNdk) {
                logger.error("Failed NDK build")
            }
            assert hasNdk : "ANDROID_NDK_HOME not set."
        }
    }

    task copyNativeLibs(type: Copy, dependsOn: "ndkBuild") {
        logger.error("Path is"+buildDir);
        from(new File('src/main/libs')) { include '**/*.so' }
        into new File(buildDir, 'native-libs')
    }

    tasks.withType(JavaCompile) {
        compileTask -> compileTask.dependsOn ndkBuild
    }
}

dependencies {
    compile 'com.android.support:support-v4:19.0.1'
    compile 'com.android.support:appcompat-v7:+'
    compile fileTree(dir: 'libs', include: ['*.jar'])
}

以下是一些错误消息

:app:ndkBuild                 
JNI LOCATION: jni             
MAKE_FILE_LOCATION:           
ZLIB Compiled                 
libpng compiling              
make: Entering directory `/Users/vikramsahai/Documents/workspace/SVS-ANDROID/SVS/app/src/main'
Install        : libharu.so => libs/armeabi/libharu.so
make: Leaving directory `/Users/vikramsahai/Documents/workspace/SVS-ANDROID/SVS/app/src/main'
:app:compileDebugJava 
cast to Object for a varargs call   
/Users/vikramsahai/Documents/workspace/SVS-ANDROID/SVS/app/src/main/java/com/vikramsahai/apps/finance/CPDF.java:255: error: cannot access Color
                a1.setBackgroundColor(new BaseColor(0xD4D4D4));
                                      ^
  class file for java.awt.Color not found
  cast to Object[] for a non-varargs call and to suppress this warning
/app/src/main/java/com/vikramsahai/apps/finance/db/Database.java:329: warning: non-varargs call of varargs method with inexact argument type for last parameter;
                                                initialValues.put(f.getName().substring(1, f.getName().length()), String.valueOf(m.invoke(obj, null))); 

为什么它会在eclipse上编译和运行并且在Android Studio / Gradle上分崩离析

是没有意义的

顶级build.gradle具有此依赖性

dependencies {
    classpath 'com.android.tools.build:gradle:0.8.+'
}

0 个答案:

没有答案