Muh*_*tar 194 android android-multidex
我想添加融合位置服务,但它显示了一些错误.帮我.
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
buildToolsVersion "27.0.1"
defaultConfig {
applicationId "com.example.adil.bloodbankapplication"
minSdkVersion 15
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:appcompat-v7:26.1.0'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
compile 'com.google.firebase:firebase-auth:11.8.0'
compile 'com.google.firebase:firebase-database:11.8.0'
compile 'com.android.support:support-v4:26.1.0'
compile 'junit:junit:4.12'
compile 'com.android.support:design:26.1.0'
compile 'com.github.joielechong:countrycodepicker:2.1.5'
compile 'com.jaredrummler:material-spinner:1.2.4'
compile 'hanks.xyz:htextview-library:0.1.5'
compile 'com.firebaseui:firebase-ui-database:1.2.0'
compile 'com.google.android.gms:play-services:11.8.0'
}
apply plugin: 'com.google.gms.google-services'
Run Code Online (Sandbox Code Playgroud)
Ale*_*Pad 247
他们给你的答案都没有详尽无遗.问题出在Multidex上.您必须在app gradle中添加库:
implementation 'com.android.support:multidex:1.0.3'
之后,添加app gradle的defaultConfig:
multiDexEnabled true
Run Code Online (Sandbox Code Playgroud)
您的应用程序必须是Multidex类型..您必须在清单中写入它:
android:name=".MyApplication"
Run Code Online (Sandbox Code Playgroud)
"MyApplication"必须是Multidex类,或者必须扩展它.
小智 124
我用下面的解决方案解决了我的问题:
实现'com.android.support:multidex:1.0.3'
multiDexEnabled是的
gsm*_*gsm 83
什么是 dex 文件: Android 应用程序 (APK) 文件包含 Dalvik 可执行文件 (DEX) 文件形式的可执行字节码文件,其中包含用于运行应用程序的编译代码。
出现此异常的原因: DEX 规范将单个 DEX 文件中可以引用的方法总数限制为 65,536(64K 引用限制)——包括 Android 框架方法、库方法和您自己代码中的方法。
Step 01. 添加如下依赖如下
对于非 Androidx 用户,
dependencies {
implementation 'com.android.support:multidex:1.0.3'
}
defaultConfig {
minSdkVersion 16
targetSdkVersion 28
multiDexEnabled true //ADD THIS LINE
}
Run Code Online (Sandbox Code Playgroud)
对于 Androidx 用户,
dependencies {
implementation 'androidx.multidex:multidex:2.0.1'
}
defaultConfig {
minSdkVersion 16
targetSdkVersion 28
multiDexEnabled true //ADD THIS LINE
}
Run Code Online (Sandbox Code Playgroud)
步骤 02:
添加这些同步项目后,在运行项目之前,请确保在运行前构建项目。否则,你会得到一个例外。
wda*_*xna 70
修改你的应用程序或模块 build.gradle
android {
defaultConfig {
...
minSdkVersion 21 <----- *here
targetSdkVersion 26
multiDexEnabled true <------ *here
}
...
}
Run Code Online (Sandbox Code Playgroud)
根据官方文件
适用于Android 5.0及更高版本的Multidex支持
Android 5.0(API级别21)及更高版本使用名为ART的运行时,它本身支持从APK文件加载多个DEX文件.ART在app安装时执行预编译,扫描classesN.dex文件并将它们编译成单个.oat文件,以供Android设备执行.因此,如果您的minSdkVersion为21或更高,则不需要multidex支持库.
有关Android 5.0运行时的更多信息,请阅读ART和Dalvik.
https://developer.android.com/studio/build/multidex
小智 36
你可以按照这个.
Android 5.0(API级别21)之前的平台版本使用Dalvik运行时来执行应用程序代码.默认情况下,Dalvik将应用程序限制为每个APK的单个classes.dex字节码文件.为了解决此限制,您可以将multidex支持库添加到项目中:
dependencies {
implementation 'com.android.support:multidex:1.0.3'
}
Run Code Online (Sandbox Code Playgroud)
如果你的minSdkVersion设置为21或更高,你需要做的就是在你的模块级build.gradle文件中将multiDexEnabled设置为true,如下所示:
android {
defaultConfig {
...
minSdkVersion 21
targetSdkVersion 28
multiDexEnabled true
}
...
}
Run Code Online (Sandbox Code Playgroud)
Pan*_*tel 24
嗨问题在这里删除它
compile 'com.google.android.gms:play-services:11.8.0'
Run Code Online (Sandbox Code Playgroud)
为什么?
注意:请勿使用组合的播放服务目标.它带来了数十个库,使您的应用程序膨胀.而是仅指定您的应用使用的特定Google Play服务API.
并使用你需要的东西.https://developers.google.com/android/guides/setup
喜欢定位服务
com.google.android.gms:play-services-location:11.8.0
Run Code Online (Sandbox Code Playgroud)
对于云消息传递
com.google.android.gms:play-services-gcm:11.8.0
Run Code Online (Sandbox Code Playgroud)
小智 23
我以这种方式解决了我同样的问题,您需要遵循 2 个简单的步骤。我是AndroidX用户,所以对我来说,首先我在我的项目的依赖项部分的build.gradle文件中实现这个依赖项。
implementation 'androidx.multidex:multidex:2.0.1'
dependencies {
//for multidex
implementation 'androidx.multidex:multidex:2.0.1'
Run Code Online (Sandbox Code Playgroud)
}
在您的build.gradle文件中添加此依赖项后,再次同步您的项目
现在添加“ defaultConfig ”部分:
multiDexEnabled true
defaultConfig {
applicationId "com.papel.helper"
minSdkVersion 16
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
multiDexEnabled true
}
Run Code Online (Sandbox Code Playgroud)
现在再次重建您的项目并运行:)
Raj*_*dav 18
如果您正在构建DEBUG APK,只需添加:
debug {
multiDexEnabled true
}
Run Code Online (Sandbox Code Playgroud)
内 buildTypes
如果您正在构建RELEASE APK,请添加
multiDexEnabled true发布块作为 -
release {
...
multiDexEnabled true
...
}
Run Code Online (Sandbox Code Playgroud)
Mos*_*lah 16
我为我的项目找到了这个解决方案,我
只是将最低 SDK 版本设置为21,这解决了我的问题
android {
defaultConfig {
...
minSdkVersion 21 //set the minimum sdk version 21
targetSdkVersion 29
}
...
}
Run Code Online (Sandbox Code Playgroud)
如果您的 minSdkVersion 为21或更高,默认情况下启用 multidex,并且您不需要 multidex 支持库。阅读更多关于 multidex https://developer.android.com/studio/build/multidex.html
小智 15
只需将此代码添加到您的应用程序或模块的 build.gradle 中
android {
defaultConfig {
...
multiDexEnabled true <------ * here
}
...
}
Run Code Online (Sandbox Code Playgroud)
Day*_*iye 14
这将为 Kotlin 或 Java 项目完成工作。
步骤 1 -在 Gradle Scripts 下找到build.gradle(Module:app)
第 2 步 - 添加multiDexEnabled true见下文:
compileSdkVersion 29
defaultConfig {
applicationId "com.example.appname"
minSdkVersion 19
targetSdkVersion 29
versionCode 1
versionName "1.0"
multiDexEnabled true //addded
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
Run Code Online (Sandbox Code Playgroud)
第 3 步 - 添加 multidex 依赖项
dependencies {
implementation 'com.android.support:multidex:2.0.0' //added
}
Run Code Online (Sandbox Code Playgroud)
最后,同步您的项目.. 享受!
小智 13
只需执行以下操作:
build.gradle
(module:app)
android {
....
defaultConfig {
multiDexEnabled true // enable mun
}
}
Run Code Online (Sandbox Code Playgroud)
并在您的build.gradle应用级文件中添加以下依赖项
dependencies {
implementation 'com.android.support:multidex:1.0.3'
}
Run Code Online (Sandbox Code Playgroud)
Ric*_*rdd 13
对于扑扑的项目,您也可以解决此问题
打开您的\ android \ app \ build.gradle
您拥有以下内容:
android {
defaultConfig {
...
minSdkVersion 16
targetSdkVersion 28
}
}
Run Code Online (Sandbox Code Playgroud)
如果将minSdkVersion设置为21或更高,则只需在defaultConfig 中将multiDexEnabled设置为true。像这样
android {
defaultConfig {
...
minSdkVersion 16
targetSdkVersion 28
multiDexEnabled true
}
}
Run Code Online (Sandbox Code Playgroud)
如果您的minSdkVersion设置为20或更低,则将multiDexEnabled true添加到defaultConfig
并定义实现
dependencies {
implementation 'com.android.support:multidex:1.0.3'// or 2.0.1
}
Run Code Online (Sandbox Code Playgroud)
最后,您应该具有:
android {
defaultConfig {
...
minSdkVersion 16
targetSdkVersion 28
multiDexEnabled true // added this
}
}
dependencies {
implementation 'com.android.support:multidex:1.0.3'
}
Run Code Online (Sandbox Code Playgroud)
有关更多信息,请阅读以下内容:https : //developer.android.com/studio/build/multidex
Kam*_*esh 11
我在 Flutter 项目中使用了以下解决方案:
打开yourproject/app/build.gradle并添加以下几行:
android {
...
defaultConfig {
...
minSdkVersion 21
multiDexEnabled true
}
}
Run Code Online (Sandbox Code Playgroud)
然后
dependencies {
...
implementation 'com.android.support:multidex:1.0.3'
}
Run Code Online (Sandbox Code Playgroud)
如果你已经迁移到AndroidX,你会想要这个:
dependencies {
...
implementation 'androidx.multidex:multidex:2.0.1'
}
Run Code Online (Sandbox Code Playgroud)
这个解决方案对我有用。感谢您提出这个问题。
你有太多的方法计数.Android dex文件限制为允许的65536种方法.
对于初学者,如果您不需要所有的Google Play服务API而只需要位置,请替换
compile 'com.google.android.gms:play-services:11.8.0'
Run Code Online (Sandbox Code Playgroud)
同
compile 'com.google.android.gms:play-services-location:11.8.0'
Run Code Online (Sandbox Code Playgroud)
您可以参考此页面以了解如何避免它或需要更多内容:https: //developer.android.com/studio/build/multidex.html
在Gradle构建文件中,添加依赖项:
implementation 'com.android.support:multidex:1.0.2'
Run Code Online (Sandbox Code Playgroud)
要么
implementation 'com.android.support:multidex:1.0.3'
Run Code Online (Sandbox Code Playgroud)
要么
implementation 'com.android.support:multidex:2.0.0'
Run Code Online (Sandbox Code Playgroud)
然后在"defaultConfig"部分中添加:
multiDexEnabled true
Run Code Online (Sandbox Code Playgroud)
在targetSdkVersion下
minSdkVersion 17
targetSdkVersion 27
multiDexEnabled true
Run Code Online (Sandbox Code Playgroud)
现在,如果您遇到此错误
错误:无法解决:multidex-instrumentation打开文件
您需要将您的gradle更改为3.0.1
classpath 'com.android.tools.build:gradle:3.0.1'
Run Code Online (Sandbox Code Playgroud)
并将以下代码放在gradle-wrapper.properties文件中
distributionUrl = HTTPS://services.gradle.org/distributions/gradle-4.1-all.zip
最后
在项目中添加类Applition并将其引入AndroidManifest,它是从MultiDexApplication扩展而来的
public class App extends MultiDexApplication {
@Override
public void onCreate( ) {
super.onCreate( );
}
Run Code Online (Sandbox Code Playgroud)
}
首先运行项目以创建错误,然后清理项目
最后,重新启动项目并享受它
小智 9
添加你的文件android/app/build.gradle
defaultConfig {
applicationId "com.ubicacion"
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode 1
versionName "1.0"
multiDexEnabled true // ?
missingDimensionStrategy 'react-native-camera', 'general'
}
Run Code Online (Sandbox Code Playgroud)
小智 8
multiDexEnabled true
Run Code Online (Sandbox Code Playgroud)
请尝试将其添加到您的应用程序defaultConfig {}中。这可以帮助我解决问题
如果您将minifyEnabled与Proguard一起使用,则可能无需启用multi-dex。我同意MG Developer的建议,如果可能,应尽量避免使用多dex。我的解决方案是仅对调试版本启用multi-dex。minifyEnabled解决了发行版本的问题
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
debug {
// getting error: Cannot fit requested classes in a single dex file. # methods: 65537 > 65536
// https://developer.android.com/studio/build/multidex
// minifyEnabled true (used with release) will fix this by getting rid of unused method calls, but this will hide debugging info on crash
multiDexEnabled true
}
}
Run Code Online (Sandbox Code Playgroud)
对于颤振
解决方案1
要解决只需将最小目标 SDK 更改minSdkVersion 16为minSdkVersion 21.
打开project/android/app/build.gradle和改变
defaultConfig {
...
minSdkVersion 21
}
Run Code Online (Sandbox Code Playgroud)
解决方案2
启用 multidex:修改project/android/app/build.gradle文件以启用 multidex 并添加 multidex 库作为依赖项,如下所示:
android {
defaultConfig {
...
multiDexEnabled true
}
...
}
dependencies {
implementation 'com.android.support:multidex:1.0.3'
}
Run Code Online (Sandbox Code Playgroud)
我不知道为什么,也许是因为我在Kotlin开发但是为了解决这个错误我最终必须创建一个MultiDexApplication像这样扩展的类:
class MyApplication : MultiDexApplication() {
}
Run Code Online (Sandbox Code Playgroud)
在我的Manifest.xml我必须设置
<application
...
android:name=".MyApplication">
Run Code Online (Sandbox Code Playgroud)
不要混淆任何人,我也这样做:
multiDexEnabled true
implementation 'com.android.support:multidex:1.0.3'
Run Code Online (Sandbox Code Playgroud)
对于androidx,这对我也有用:
implementation 'androidx.multidex:multidex:2.0.0'
Run Code Online (Sandbox Code Playgroud)
...
<application android:name="android.support.multidex.MultiDexApplication">
不适合我
当您使用依赖项时,您的方法就会增加!谷歌有一个解决方案。那叫Multidex!
注意:请确保最小SDK超过14。
在您的build.gradle中:
android {
defaultConfig {
...
minSdkVersion 15
targetSdkVersion 28
multiDexEnabled true
}
...
}
dependencies {
implementation 'com.android.support:multidex:1.0.3'
}
Run Code Online (Sandbox Code Playgroud)
供androidx使用:
implementation 'com.android.support:multidex:1.0.3'
Run Code Online (Sandbox Code Playgroud)
欲了解更多信息,请访问原始链接:
https://developer.android.com/studio/build/multidex
小智 5
我遇到过两次这个错误,解决方法是;检查您的应用程序 gradle 文件以查看您的目标 SDk,如果它是 20 或更高,只需在您的defaultconfig { multiDexEnabled true }
否则,如果您的 targetSDK 小于 20,请将该行添加到您的 defaultConfig 并添加一个依赖项
implementation 'com.android.support:multidex:1.0.3'.
Run Code Online (Sandbox Code Playgroud)
查看此链接了解更多信息。
https://developer.android.com/studio/build/multidex#mdex-gradle
使用 multidex 支持应该是最后的手段。默认情况下,gradle build 将为您的 APK 收集大量的传递依赖项。按照Google Developers Docs 中的建议,首先尝试从项目中删除不必要的依赖项。
使用命令行导航到 Android Projects Root。您可以按如下方式获取编译依赖树。
gradlew app:dependencies --configuration debugCompileClasspath
Run Code Online (Sandbox Code Playgroud)
您可以获得依赖树的完整列表
gradlew app:dependencies
Run Code Online (Sandbox Code Playgroud)
然后从您的应用 build.gradle 中删除不必要的或可传递的依赖项。例如,如果您的应用程序使用名为“com.google.api-client”的依赖项,您可以排除不需要的库/模块。
implementation ('com.google.api-client:google-api-client-android:1.28.0'){
exclude group: 'org.apache.httpcomponents'
exclude group: 'com.google.guava'
exclude group: 'com.fasterxml.jackson.core'
}
Run Code Online (Sandbox Code Playgroud)
然后在 Android Studio 中选择 Build > Analyze APK... 选择发布/调试 APK 文件以查看内容。这将为您提供方法和引用计数,如下所示。
| 归档时间: |
|
| 查看次数: |
154664 次 |
| 最近记录: |