Android Studio构建工作,Gradle命令行失败 [英] Android Studio build works, Gradle command line fails

查看:108
本文介绍了Android Studio构建工作,Gradle命令行失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经将Eclipse中的应用程序移植到Android Studio中,实现了我需要的功能,并允许它在Android Studio中工作。由于我喜欢使用命令行Gradle构建它的味道数量。但是,当我运行以下命令来构建我的发行版APK时

  gradlew.bat assembleRelease 




$ b

出现以下错误:

  FAILURE :构建失败,出现异常。 

*其中:
构建文件'C:\whatever\build.gradle'行:1

*出错:
A评估项目'MyCompany'出现问题。
> java.lang.UnsupportedClassVersionError:com / android / build / gradle / AppPlugin:不支持major.minor版本52.0

*尝试:
使用--stacktrace选项运行以获取堆栈跟踪。使用--info或--debug选项运行以获取更多日志输出。

BUILD FAILED

我使用--stacktrace和--debug并且它确实不提供任何其他信息,除了将错误指向build.gradle的第一行:

  apply plugin:'com.android.application'

我尝试了以下基于其他stackoverflow响应到这个错误:


  1. 升级到JavaVersion.VERSION_1_8

  2. 添加Jack build.gradle(和这会降低所有内容的速度,但是对于1.8版本而言,即使它已被弃用,它也是必需的)
  3. 增加堆内存( org.gradle.jvmargs = -Xmx4096m )和dex( javaMaxHeapSize4g)。

我正在运行 Android Studio 2.3.3



这是我的 build.gradle 文件。为了节省空间,我只留下了几个口味,并且重新命名了一些保护无辜者的东西。如果这可能是问题,我已经留在依赖关系中了?唯一的乐趣是我正在重命名APK并将其推送到不同的文件夹,但是当我直接从Android Studio运行发布版本时,这一切都正常工作。 build.gradle

  apply plugin:'com.android。 '
apply plugin:'io.fabric'

buildscript {
repositories {
maven {url'https://maven.fabric.io/public' }
}

依赖关系{
classpath'io.fabric.tools:gradle:1.+'
}
}

repositories {
maven {url'https://maven.fabric.io/public'}
}


android {
signingConfigs {
config {
keyAlias'whatever'
keyPassword'imnotgoingtotellyou'
storeFile文件('C:/whereever/mycompany.keystore')
storePassword'yeps'


compileSdkVersion 25
buildToolsVersion '25 .0.3'
defaultConfig {
jackOptions {
enabled true
additionalParameters('jack .incremental':'true')
}
applicationIdcom.mycompany.default
minSdkVersion 14
targetSdkVersion 23
versionCode 44
versionName2.1.44
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8}
signingConfig signingConfigs.config
}
dexOptions {
javaMaxHeapSize4g
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'),'proguard-rules.txt'
signingConfig signingConfigs.config
}
}
productFlavors.whenObjectAdded {flavor - >
flavor.ext.set('directoryPath','')
flavor.ext.set('apkName','')
}
productFlavors {

Flavor1 {
signingConfig signingConfigs.config
directoryPath ='flavor1'
}

Flavor2 {
applicationId'com.mycompany.flavor2'
signingConfig signingConfigs.config
directoryPath ='flavor2'
}

applicationVariants.all {variant - >
variant.outputs.each {输出 - >
def path =C:/AndroidBuilds/MyBuild.Build/+ variant.productFlavors [0] .directoryPath +/
logger.error(Path =+ path)
def SEP = -
def apkName = variant.productFlavors [0] .apkName
def flavor = variant.productFlavors [0] .name $ b $ if(apkName!='')
flavor = apkName;
def version = variant.versionCode
def newApkName = path + version + SEP + flavor
logger.error(newApkName =+ newApkName)
output.outputFile = new File( newApkName +.apk)
}
}
}

依赖关系{
编译项目(':androidpdfview100')
编译' com.android.support:support-v13:25.3.1'
compile'c​​om.google.code.gson:gson:2.7'
compile'joda-time:joda-time:2.5'
编译'com.google.android.gms:play-services-maps:11.0.4'
编译文件('libs / httpmime-4.2.5.jar')
编译文件('libs /itextg-5.4.4.jar')
编译文件('libs / js.jar')
编译文件('libs / logentries-android-2.1.1.jar')
编译文件('libs / universal-image-loader-1.8.6.jar')
编译文件('libs / xmlworker-5.4.4.jar')
编译文件('libs / zbar。 jar')
compile('com.crashlytics .sdk.android:crashlytics:2.6.8@aar'){
transitive = true;
}
}

更新



项目结构如下所示:



当我从Eclipse移植代码时,它是由Android Studio自动生成的:





像这样:



解决方案

对于将来面临此问题的任何人,为了确保您的 JAVAHOME 设置为JDK v8:

  JAVAHOME = C:\程序文件\Java\jdk1.8.0_112 

或者您的 1.8 JDK 是。这是一个野兽,并吸取记忆,但它是解决这个构建错误的唯一方法。我不建议你用1.8版本构建Android Studion,因为它似乎需要 Jack ,这只是很慢。可悲的是,它已被弃用启动。

I have ported an app from Eclipse to Android Studio, implemented my needed flavors and have it allow working in Android Studio. Due to the number of flavors I would prefer to build it using command line Gradle. However when I run the following command to build my release APKs

gradlew.bat assembleRelease

I get the following error:

FAILURE: Build failed with an exception.

* Where:
Build file 'C:\whatever\build.gradle' line: 1

* What went wrong:
A problem occurred evaluating project ':MyCompany'.
> java.lang.UnsupportedClassVersionError: com/android/build/gradle/AppPlugin : Unsupported major.minor version 52.0

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED

I have run with --stacktrace and --debug and it really does not offer any other information, other than pointing the error to be with the first line of the build.gradle:

apply plugin: 'com.android.application'

I have attempted the following based on other stackoverflow responses to this error:

  1. Upgraded to JavaVersion.VERSION_1_8
  2. Added Jack the build.gradle (and that slowed everything down, but it was required for 1.8, even though it is deprecated?)
  3. Increased memory for heap (org.gradle.jvmargs=-Xmx4096m) and dex (javaMaxHeapSize "4g").

I am running Android Studio 2.3.3

Here is my build.gradle file. I have left only a couple of the flavors to save space, and renamed some of the stuff to protect the innocent. I have left in the dependencies in case that might be the problem? The only funkiness is that I am renaming the APK and pushing it to a different folder, but that is all working when I run the release build directly out of Android Studio. The build.gradle:

apply plugin: 'com.android.application'
apply plugin: 'io.fabric'

buildscript {
    repositories {
        maven { url 'https://maven.fabric.io/public' }
    }

    dependencies {
        classpath 'io.fabric.tools:gradle:1.+'
    }
}

repositories {
    maven { url 'https://maven.fabric.io/public' }
}


android {
    signingConfigs {
        config {
            keyAlias 'whatever'
            keyPassword 'imnotgoingtotellyou'
            storeFile file('C:/whereever/mycompany.keystore')
            storePassword 'yeps'
        }
    }
    compileSdkVersion 25
    buildToolsVersion '25.0.3'
    defaultConfig {
        jackOptions {
            enabled true
            additionalParameters('jack.incremental': 'true')
        }
        applicationId "com.mycompany.default"
        minSdkVersion 14
        targetSdkVersion 23
        versionCode 44
        versionName "2.1.44"
        compileOptions {
            sourceCompatibility JavaVersion.VERSION_1_8
            targetCompatibility JavaVersion.VERSION_1_8        }
        signingConfig signingConfigs.config
    }
    dexOptions {
        javaMaxHeapSize "4g"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
            signingConfig signingConfigs.config
        }
    }
    productFlavors.whenObjectAdded { flavor ->
        flavor.ext.set('directoryPath', '')
        flavor.ext.set('apkName', '')
    }
    productFlavors {

        Flavor1 {
            signingConfig signingConfigs.config
            directoryPath = 'flavor1'
        }

        Flavor2 {
            applicationId 'com.mycompany.flavor2'
            signingConfig signingConfigs.config
            directoryPath = 'flavor2'
        }

    applicationVariants.all { variant ->
        variant.outputs.each { output ->
            def path = "C:/AndroidBuilds/MyBuild.Build/" + variant.productFlavors[0].directoryPath + "/"
            logger.error("Path = " + path)
            def SEP = "-"
            def apkName = variant.productFlavors[0].apkName
            def flavor = variant.productFlavors[0].name
            if (apkName != '')
                flavor = apkName;
            def version = variant.versionCode
            def newApkName = path + version + SEP + flavor
            logger.error("newApkName = " + newApkName)
            output.outputFile = new File(newApkName + ".apk")
        }
    }
}

dependencies {
    compile project(':androidpdfview100')
    compile 'com.android.support:support-v13:25.3.1'
    compile 'com.google.code.gson:gson:2.7'
    compile 'joda-time:joda-time:2.5'
    compile 'com.google.android.gms:play-services-maps:11.0.4'
    compile files('libs/httpmime-4.2.5.jar')
    compile files('libs/itextg-5.4.4.jar')
    compile files('libs/js.jar')
    compile files('libs/logentries-android-2.1.1.jar')
    compile files('libs/universal-image-loader-1.8.6.jar')
    compile files('libs/xmlworker-5.4.4.jar')
    compile files('libs/zbar.jar')
    compile('com.crashlytics.sdk.android:crashlytics:2.6.8@aar') {
        transitive = true;
    }
}

UPDATE

The project structure looks like this:

It was generated automatically by Android Studio when I ported the code from Eclipse:

When you drill into the App itself it looks like this:

解决方案

For anyone facing this issue in the future, for the command line build make sure your JAVAHOME is set to JDK v8:

JAVAHOME=C:\Program Files\Java\jdk1.8.0_112

Or where ever your 1.8 JDK is. It is a beast and sucks up memory but it was the only way to get around this build error. I would NOT recommend that you build in Android Studion with 1.8 since it seems to require Jack which is just plain slow. And sadly it is deprecated to boot.

这篇关于Android Studio构建工作,Gradle命令行失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆