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:
- Upgraded to JavaVersion.VERSION_1_8
- Added Jack the build.gradle (and that slowed everything down, but it was required for 1.8, even though it is deprecated?)
- 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:

