Android Studio ignore --core-library flag

隐身守侯 提交于 2019-11-28 00:53:14

The syntax for specifying dexOptions values is different; you need an equals sign:

dexOptions {
    coreLibrary = true;
}
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!

Bageshwar Pratap Narain

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
    }
}

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.

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

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.

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'
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!