Android Studio ignore --core-library flag

前端 未结 6 841
盖世英雄少女心
盖世英雄少女心 2020-12-06 17:40

I have a project, which i want to configure on my computer.

On anothe computer it works, but with old version of Android Studio 0.4.0 whenever I use 0.5.2

Th

相关标签:
6条回答
  • 2020-12-06 17:47

    You will have to exclude libraries which are causing this issue. For Example: -

    compile('org.simpleframework:simple-xml:2.7.+'){
        exclude module: 'stax'
        exclude module: 'stax-api'
        exclude module: 'xpp3'
    }
    
    0 讨论(0)
  • 2020-12-06 17:50

    In Android Studio 1.1.0, navigate to :

    File --> Other Settings --> Default Settings --> Compilers --> Android Compilers

    You will find the check-box to Add "--core-library" flag, but this does not seem to be working.

    Instead editing the file app/build.gradle

    Disabling pre-dexing inside android {} using

    dexOptions {
        preDexLibraries = false
    }
    

    and modifying Dex task using

    project.tasks.withType(com.android.build.gradle.tasks.Dex) {
        additionalParameters=['--core-library']
    }
    

    solves the problem.

    Edit: Full contents of app/build.gradle

    apply plugin: 'com.android.application'
    
    android {
        compileSdkVersion 21
        buildToolsVersion "21.1.2"
    
        defaultConfig {
            applicationId "appId"
            minSdkVersion 19
            targetSdkVersion 21
            versionCode 1
            versionName "1.0"
            multiDexEnabled true
        }
    
        buildTypes {
            release {
                minifyEnabled false
                proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            }
        }
    
        dexOptions {
            preDexLibraries = false
            javaMaxHeapSize "4g"
        }
    
        project.tasks.withType(com.android.build.gradle.tasks.Dex) {
            additionalParameters=['--core-library']
        }
    
        packagingOptions {
            exclude 'META-INF/LICENSE'
            exclude 'META-INF/NOTICE'
            exclude 'META-INF/MANIFEST.MF'
            exclude 'META-INF/DEPENDENCIES'
            exclude 'META-INF/LICENSE.txt'
            // more exclude files here if conflicts
        }
    }
    
    0 讨论(0)
  • 2020-12-06 17:55
    project.tasks.withType(com.android.build.gradle.tasks.Dex) {
        additionalParameters=['--core-library']
    }
    

    does not work proper,and get the error:

    Could not get unknown property 'com' for object of type com.android.build.gradle.AppExtension.

    I solve the problem by adding this to android block.

    dexOptions {
        preDexLibraries = false
        additionalParameters=['--core-library']
    }
    

    Hoping this is helpful to you!

    0 讨论(0)
  • 2020-12-06 18:01

    I think we cannot enable --core-library via dexOptions.

    We know that dexOptions delegated to a com.android.build.gradle.internal.dsl.DexOptions object, which implements com.android.builder.core.DexOptions.

    From the source code, we know it doesn't support --core-library.

    From Issue 79280: dexOptions in gradle plugin don't support coreLibrary

    You can do it manually by

    • disable pre-dexing (this is because our cache would have issues if we allow adding extra params)
    • modify the Dex tasks to add --core-library as an extra parameters.
    0 讨论(0)
  • 2020-12-06 18:06

    I solved this problem! Unfortunately I solved it only by installing version Android Studio 0.4.2.... Other methods didn't help... Probably, later, it is better to configure project for new version of Android Studio.

    0 讨论(0)
  • 2020-12-06 18:11

    Hi I have the same problem and I resolved it by checked the box "Add --core-library" in /Preferences/Compiler/Android Compilers

    0 讨论(0)
提交回复
热议问题