android: error when trying to use java 8

2

I'm trying to upload the java version (to java 8), in my build.gradle(Module:app) I added the following:

apply plugin: 'com.android.application'
android {
    compileSdkVersion 24
    buildToolsVersion "24.0.2" 
    defaultConfig {
        applicationId "xxx.xxx.xxx.xx"
        minSdkVersion 15
        targetSdkVersion 24
        versionCode 1
        versionName "1.0"
        jackOptions {
            enabled true
        }
    }
    compileOptions {
        encoding "UTF-8"
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
        debug {
        }
    }
}
dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    testCompile 'junit:junit:4.12'
    repositories {
        mavenCentral()
    }
    compile project(path: ':slide')
    compile 'com.android.support:appcompat-v7:24.2.1'
    compile 'com.google.android.gms:play-services-maps:9.6.1'
    compile 'com.google.android.gms:play-services-ads:9.6.1'
    compile 'com.google.android.gms:play-services-auth:9.6.1'
    compile 'com.android.support:design:24.2.1'
    compile 'com.android.support:support-v4:24.2.1'
    compile 'com.android.support:recyclerview-v7:24.2.1'
}
apply plugin: 'com.google.gms.google-services'

But when trying to run the app I get "Gradle Build Runing" and it does not happen there.

What is the reason for this situation?

    
asked by devjav 01.12.2016 в 21:24
source

2 answers

0

It is not possible to use Java 8 in a normal way because another compiler is required that translates to version 7 because it is the current support level. The compiler is called Jack and you can find it here . Once installed and configured, the module's build.gradle includes:

android {
  ...
  defaultConfig {
    ...
    jackOptions {
      enabled true
    }
  }
  ...
}

If all you need are lambda expressions, you can use Retrolambda

    
answered by 02.12.2016 в 02:47
0

If you change from version to java 8 you should have no problem in Android Studio using at least version 2.1, only ensure using a version of Android Build Tools 24 or later, the same for targetSdkVersion in your project should be set to 24.

If your Androis Studio does not continue, try this option, what it does is that it does not download the dependencies, it could be that for some reason you can not download them.

On the menu go to: File - > Settings - > Build, Execution, Deployment - > Build Tools - > Gradle .

Select the option: 'Offline work'

    
answered by 02.12.2016 в 05:10