Android studio 1.4 和矢量图
今天我将 android studio 更新到 1.4 版本.我在更改日志中看到,您也可以为 api < 编译带有矢量图像的应用程序.21. 我试过了.我将 gradle 版本从 1.3.0 更改为 1.4.1 并实现了矢量图像而不是光栅.在构建过程中,我收到此错误:
Today I up to date android studio to 1.4 version. I saw in the changelog that you can compile an app with vector image also for api < 21. I tried it. I changed the gradle version from 1.3.0 to 1.4.1 and implemented vector image instead of raster. During building process I get this error:
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
抱歉我的英语不好.我希望你明白.提前致谢.
Sorry for my bad english. I hope you understand. Thanks in advance.
Step 1. 首先尝试 Cleaning &重新启动您的项目,看看它是否适合您.在大多数情况下,它会解决您的问题.
Step 1. First try out Cleaning & restarting your Project and see if it works out for you. In mostly cases it will solve out your issues.
第 2 步.如果这些都不适合您,则意味着您必须启用 MultiDex 模式.
Step 2. If none of this works out for you that means you will have to enabled MultiDex mode.
Multidex 支持 Android 5.0 及更高版本
Android 5.0 及更高版本使用称为 ART 的运行时支持从应用程序 APK 文件加载多个 dex 文件.艺术在应用程序安装时执行预编译,扫描classes(..N).dex 文件并将它们编译成单个 .oat 文件由 Android 设备执行.有关 Android 的更多信息5.0 运行时,请参阅 ART 简介.
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 或更高级别上正常运行.
That means your app would working fine on API level 21 or above.
Android 5.0 之前的 Multidex 支持
Android 5.0 之前的平台版本使用 Dalvik 运行时用于执行应用程序代码.默认情况下,Dalvik 将应用程序限制为单个每个 APK 的 classes.dex 字节码文件.为了解决这个问题限制,您可以使用 multidex 支持库,它变成应用程序主要 DEX 文件的一部分,然后管理对额外的 DEX 文件及其包含的代码.
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.
因此,首先确保您导入了正确的依赖项,这似乎可以通过以下方式完成.
So, Firstly making sure you have imported correct dependency, which It seems you could do by below way.
dependencies {
// Change as per the latest dependency
compile 'com.android.support:multidex:1.0.1'
}
在您的清单中,将 multidex 支持库中的 MultiDexApplication
类添加到应用程序元素中.
In your manifest add the MultiDexApplication
class from the multidex support library to the application element.
<?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)
code> 启用 multidex
.
Alternative to that, If your app extends the Application
class, you can override the attachBaseContext()
method and call MultiDex.install(this)
to enable multidex
.
public void onCreate(Bundle arguments) {
MultiDex.install(getTargetContext());
super.onCreate(arguments);
...
}
最后,您需要通过添加 multiDexEnabled true
来更新您的 build.gradle 文件,如下所示:
Finally, you will need to update your build.gradle file as below by adding multiDexEnabled true
:
defaultConfig {
applicationId '{Project Name}'
minSdkVersion 15
targetSdkVersion 23
versionCode 1
versionName "1.0"
multiDexEnabled true
}
希望能帮到你.