Android studio 1.4 和矢量图

标签 android vector android-studio

今天我将 android studio 更新到 1.4 版本。我在变更日志中看到,您也可以为 api < 21 编译带有矢量图像的应用程序。我试过了。我将 gradle 版本从 1.3.0 更改为 1.4.1 并实现了矢量图像而不是光栅图像。在构建过程中出现此错误:

Error:Execution failed for task ':app:transformClassesWithDexForDebug'.
> com.android.build.transform.api.TransformException: com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'C:\Program Files\Java\jdk1.8.0_51\bin\java.exe'' finished with non-zero exit value 2

抱歉我的英语不好。我希望你明白。提前致谢。

最佳答案

第 1 步。首先尝试清理并重新启动您的项目,看看它是否适合您。在大多数情况下,它会解决您的问题。

第 2 步。如果这些都不适合您,则意味着您必须启用 MultiDex 模式。

对 Android 5.0 及更高版本的 Multidex 支持

Android 5.0 and higher uses a runtime called ART which natively supports loading multiple dex files from application APK files. ART performs pre-compilation at application install time which scans for classes(..N).dex files and compiles them into a single .oat file for execution by the Android device. For more information on the Android 5.0 runtime, see Introducing ART.

这意味着您的应用可以在 API 级别 21 或更高级别上正常运行。

Android 5.0 之前的 Multidex 支持

Versions of the platform prior to Android 5.0 use the Dalvik runtime for executing app code. By default, Dalvik limits apps to a single classes.dex bytecode file per APK. In order to get around this limitation, you can use the multidex support library, which becomes part of the primary DEX file of your app and then manages access to the additional DEX files and the code they contain.

所以,首先确保你导入了正确的依赖项,这似乎可以通过以下方式完成。

dependencies {
  // Change as per the latest dependency
  compile 'com.android.support:multidex:1.0.1'
}

在您的 list 中,将 multidex 支持库中的 MultiDexApplication 类添加到应用程序元素。

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.android.multidex.myapplication">
    <application
        ...
        android:name="android.support.multidex.MultiDexApplication">
        ...
    </application>
</manifest>

或者,如果您的应用扩展了 Application 类,您可以覆盖 attachBaseContext() 方法并调用 MultiDex.install(this) 以启用 multidex

public void onCreate(Bundle arguments) {
    MultiDex.install(getTargetContext());
    super.onCreate(arguments);
    ...
}

最后,您需要通过添加 multiDexEnabled true 来更新您的 build.gradle 文件:

defaultConfig {  
        applicationId '{Project Name}'  
        minSdkVersion 15  
        targetSdkVersion 23  
        versionCode 1  
        versionName "1.0"  
        multiDexEnabled true  
    }  

希望对您有所帮助。

关于Android studio 1.4 和矢量图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32889059/

相关文章:

java - 定期更新 Android 应用程序中的 TextView

android - 错误 400 : Invalid Value, 无效

c++ - 如何在boost python中访问 vector

android - Genymotion 2.7 模拟器拒绝连接到 ADB

php - 在真实设备上测试我的 Android 应用程序

java - android studio 需要很多时间来打开项目?

android - 更改 .so 库中的函数名称

android - 具有 flavor 的ext变量不适用于多维

c++ - 为什么 vector 运算符+之后的虚拟值?

c++ - 有什么方法可以使用原始字节 vector 作为 boost 序列化的存档?