问题 Android Studio忽略--core-library标志


我有一个项目,我想在我的计算机上配置。

在其他计算机上它可以工作,但每当我使用0.5.2时,使用旧版Android Studio 0.4.0

问题是我启动应用程序后显示错误

构建脚本错误,找不到支持的Gradle DSL方法:'coreLibrary()'!           可能的原因可能是:
           - 您正在使用没有方法的Gradle版本            - 您没有应用提供该方法的Gradle插件            - 或者构建脚本中存在错误

但为了使它工作,我必须使用这个标志!我已经尝试在设置> Android编译器>“添加 - 核心库”标志中启用它,但它没用...

在gradle我有下一部分代码:

    dexOptions {
    coreLibrary true;
}

此错误仅在激活此行后显示...如果没有它们,则无效...

我应该如何修复这个?也许这是因为不同的版本..如果是的话那么我应该如何写它才能使它工作?

更改为coreLibrary = true之后它会在运行--core-library标志使用后编译Gradle fine BUt stille需要....但我已经在设置中将其设置为true ...

它显示不是几乎相同的错误:

Error:Execution failed for task ':BusKg:preDexDebug'.
> com.android.ide.common.internal.LoggedErrorException: Failed to run command:
    D:\Programms\Programms\adt-bundle-windows-x86_64-20131030\sdk\build-tools\android-4.4\dx.bat --dex --output D:\Android2\BUS.kg\marshrutka\BusKg\build\pre-dexed\debug\annotations-api-6.0.26-27e56569b50edbdd453f9bc0e568cde1fbfa621b.jar C:\Users\Viacheslav\.gradle\caches\modules-2\files-2.1\org.apache.tomcat\annotations-api\6.0.26\50aeafa144ed17913ed44d18ac61afd505a9e3e\annotations-api-6.0.26.jar
Error Code:
    1
Output:
    trouble processing "javax/xml/ws/WebServiceRef.class":
    Ill-advised or mistaken usage of a core class (java.* or javax.*)
    when not building a core library.
    This is often due to inadvertently including a core library file
    in your application's project, when using an IDE (such as
    Eclipse). If you are sure you're not intentionally defining a
    core class, then this is the most likely explanation of what's
    going on.
    However, you might actually be trying to define a class in a core
    namespace, the source of which you may have taken, for example,
    from a non-Android virtual machine project. This will most
    assuredly not work. At a minimum, it jeopardizes the
    compatibility of your app with future versions of the platform.
    It is also often of questionable legality.
    If you really intend to build a core library -- which is only
    appropriate as part of creating a full virtual machine
    distribution, as opposed to compiling an application -- then use
    the "--core-library" option to suppress this error message.
    If you go ahead and use "--core-library" but are in fact
    building an application, then be forewarned that your application
    will still fail to build or run, at some point. Please be
    prepared for angry customers who find, for example, that your
    application ceases to function once they upgrade their operating
    system. You will be to blame for this problem.
    If you are legitimately using some code that happens to be in a
    core package, then the easiest safe alternative you have is to
    repackage that code. That is, move the classes in question into
    your own package namespace. This means that they will never be in
    conflict with core system classes. JarJar is a tool that may help
    you in this endeavor. If you find that you cannot do this, then
    that is an indication that the path you are on will ultimately
    lead to pain, suffering, grief, and lamentation.
    1 error; aborting

在此先感谢任何帮助......


10760
2018-06-11 12:47


起源

你确定你要这么做吗?此错误消息似乎非常可怕。 - Scott Barta
嗯...我想至少启动项目,之后尝试解决这个问题......但不幸的是我甚至不知道如何启用这个核心库 - kimslava93
如果您还没有深入了解发生了什么,并且知道您需要此标志的原因非常具体,那么您可能不需要它。特别是,WebServiceRef是J2EE Web服务的注释,它几乎没有在Android应用程序中占有一席之地。我认为你想要做的事情可能在Android中没有任何意义。 - Scott Barta


答案:


指定dexOptions值的语法不同;你需要一个等号:

dexOptions {
    coreLibrary = true;
}

-4
2018-06-11 16:30



谢谢!它有助于编译gradle!它不会显示有关不受支持的coreLibrary的错误!但它还是要求使用--core-library ... - kimslava93
你确定Gradle实际上支持这个标志吗?我没有看到任何关于它的文件。 - Scott Barta
我实际上不确定......但我在下面我的问题中添加了它显示的内容......并且因为它已经准备好了项目...以前的开发人员说我要用它... - kimslava93
'='等号不需要。没有'='的Gradle插入值。 - theWook
为什么这标记为已接受的答案? - m0skit0


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

不正常工作,并得到错误:

无法为com.android.build.gradle.AppExtension类型的对象获取未知属性'com'。

我通过将其添加到android块来解决问题。

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

希望这对你有所帮助!


12
2017-10-18 08:00



仅使用additionalParameters的dexOptions对我有用。谢谢 - Sriram


在Android Studio 1.1.0中,导航至:

文件 - >其他设置 - >默认设置 - >编译器 - > Android编译器

您将找到添加“--core-library”标志的复选框,但这似乎不起作用。

而是编辑文件app / build.gradle

内部禁用预先dexing android {} 运用

dexOptions {
    preDexLibraries = false
}

并修改 Dex task 运用

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

解决了这个问题。

编辑: 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
    }
}

5
2017-12-10 06:29



你能表现得好吗? AndroidManifest.xml 文件? - 4ntoine
此更改不在AndroidManifest.xml中,而是在app / build.gradle中。使用文件内容更新答案。 - Bageshwar Pratap Narain
不再适用于AndroidStudio 1.5 - Mike Sokolov


我想我们不能启用 --core-library 通过 dexOptions

我们知道 dexOptions 委托给一个 com.android.build.gradle.internal.dsl.DexOptions 对象,实现 com.android.builder.core.DexOptions

从源代码中,我们知道它不支持 --core-library

问题79280:gradle插件中的dexOptions不支持coreLibrary

你可以手动完成

  • 禁用pre-dexing(这是因为如果我们允许添加额外的参数,我们的缓存就会出现问题)
  • 修改Dex任务以添加--core-library作为额外参数。

2
2017-09-17 12:48





嗨我有同样的问题,我通过选中/ Preferences / Compiler / Android Compilers中的“添加--core-library”框来解决它


1
2018-06-18 05:34



错误:无法完成Gradle执行。原因:未知的命令行选项'--core-library'。 - Alberto M


我解决了这个问题!不幸的是我只是通过安装Android Studio 0.4.2版本来解决它....其他方法没有帮助......可能,稍后,最好为新版本的Android Studio配置项目。


0
2018-02-21 14:27





您必须排除导致此问题的库。例如: -

compile('org.simpleframework:simple-xml:2.7.+'){
    exclude module: 'stax'
    exclude module: 'stax-api'
    exclude module: 'xpp3'
}

-1