Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/220.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 错误:无法在单个索引文件中容纳请求的类。请尝试提供主索引列表。#方法:72477>;65536_Android_Android Multidex - Fatal编程技术网

Android 错误:无法在单个索引文件中容纳请求的类。请尝试提供主索引列表。#方法:72477>;65536

Android 错误:无法在单个索引文件中容纳请求的类。请尝试提供主索引列表。#方法:72477>;65536,android,android-multidex,Android,Android Multidex,我想添加融合定位服务,但它显示了一些错误。 帮帮我 apply plugin: 'com.android.application' android { compileSdkVersion 26 buildToolsVersion "27.0.1" defaultConfig { applicationId "com.example.adil.bloodbankapplication" minSdkVersion 15 ta

我想添加融合定位服务,但它显示了一些错误。 帮帮我

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'

你的方法太多了。 Android dex文件允许使用的方法限制为65536种

首先,如果您不需要所有的google play服务API,只需要位置,请替换

compile 'com.google.android.gms:play-services:11.8.0'

您可以参考本页了解避免这种情况的方法,或者在需要时允许更多:

问题出在这里,请将其删除

compile 'com.google.android.gms:play-services:11.8.0'
为什么?

注意:不要使用组合播放服务目标。它引入了几十个库,使应用程序膨胀。相反,只指定应用程序使用的特定Google Play services API

使用你需要的东西

喜欢定位服务吗

com.google.android.gms:play-services-location:11.8.0
用于云消息传递

com.google.android.gms:play-services-gcm:11.8.0

他们给你的答案没有一个是详尽无遗的。 问题在于多重索引。 您必须在应用程序中添加库gradle:

implementation 'com.android.support:multidex:1.0.3'
multiDexEnabled true
之后,添加应用程序gradle的defaultConfig:

implementation 'com.android.support:multidex:1.0.3'
multiDexEnabled true
您的应用程序必须是Multidex类型。。 您必须将其写入清单:

android:name=".MyApplication"

“MyApplication”必须是Multidex类,或者必须扩展它。

我用以下解决方案解决了我的问题:

在渐变生成文件中,添加依赖项: 实现'com.android.support:multidex:1.0.3'

然后在“defaultConfig”部分,添加: 多索引启用真


如果您正在构建调试APK,只需添加:

debug {
            multiDexEnabled true
        }
内部
buildTypes

如果您正在构建发布APK,请添加 发布块中的
multiDexEnabled true
as-

release {
                ...
                multiDexEnabled true
                ...
        }

我不知道为什么,也许是因为我在Kotlin开发,但为了修复这个错误 最后,我必须创建一个扩展
MultiDexApplication
的类,如下所示:

class MyApplication : MultiDexApplication() {
}
在我的
Manifest.xml
中,我必须设置

<application
        ...
        android:name=".MyApplication">
对于androidx,这也适用于我:

implementation 'androidx.multidex:multidex:2.0.0'


不适用于我

修改你的应用程序或模块的
build.gradle

android {
    defaultConfig {
        ...
        minSdkVersion 21 <----- *here
        targetSdkVersion 26
        multiDexEnabled true <------ *here
    }
    ...
}
android{
默认配置{
...

MinsdkVersion21我所要做的就是在文件>项目结构>应用程序>口味中将最小SDK版本设置为21在Gradle构建文件中,添加依赖项:

implementation 'com.android.support:multidex:1.0.2'

然后在“defaultConfig”部分,添加:

multiDexEnabled true
在targetSdkVersion下

minSdkVersion 17
targetSdkVersion 27
multiDexEnabled true
现在如果你遇到这个错误

错误:无法解析:multidex检测打开文件

您需要将渐变更改为3.0.1

classpath 'com.android.tools.build:gradle:3.0.1'
并将以下代码放入文件gradle-wrapper.properties中

分配=https://services.gradle.org/distributions/gradle-4.1-all.zip

最后

在项目中添加类application并将其引入AndroidManifest 它是从多索引应用程序扩展而来的

public class App extends MultiDexApplication {

    @Override
    public void onCreate( ) {
        super.onCreate( );
    }
}
首先运行项目以创建错误,然后清除项目


最后,重新启动项目并享受它

我两次遇到这个错误,解决方法是:检查你的app gradle文件以查看你的目标SDk,如果它是20或更高,只需在你的
defaultconfig{multiDexEnabled true}

否则,如果targetSDK小于20,则将该行添加到defaultConfig,并添加依赖项

implementation 'com.android.support:multidex:1.0.3'.
查看此链接了解更多信息

请尝试在您的应用程序defaultConfig{}中添加此项。这有助于我解决您可以遵循的问题

Android 5.0(API级别21)之前的平台版本使用Dalvik运行时执行应用程序代码。默认情况下,Dalvik将应用程序限制为每个APK的单个class.dex字节码文件。为了克服此限制,您可以将multidex支持库添加到您的项目中:

dependencies {
  implementation 'com.android.support:multidex:1.0.3'
}
如果minSdkVersion设置为21或更高,则只需在模块级build.gradle文件中将multiDexEnabled设置为true,如下所示:

android {
    defaultConfig {
        ...
        minSdkVersion 21 
        targetSdkVersion 28
        multiDexEnabled true
    }
    ...
}
只需执行以下操作:

android {
    defaultConfig {
        ...
        minSdkVersion 16
        targetSdkVersion 28

    }

}
格雷德尔先生

并在
build.gradle
app级文件中添加以下依赖项

dependencies {
    implementation 'com.android.support:multidex:1.0.3'
} 
内置:应用程序

apply plugin: 'com.android.application'
android {
compileSdkVersion 28
defaultConfig {
    applicationId "com.proyecto.marketdillo"
    minSdkVersion 14
    targetSdkVersion 28
    versionCode 1
    versionName "1.0"
    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    multiDexEnabled true
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
    }
  }
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0-rc02'
implementation 'com.google.firebase:firebase-core:16.0.7'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'com.android.support:support-v4:28.0.0-rc02'
implementation 'com.android.support:design:28.0.0-rc02'
implementation 'com.google.firebase:firebase-auth:16.1.0'
implementation 'com.squareup.picasso:picasso:2.5.2'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
implementation 'com.google.firebase:firebase-firestore:17.1.5'
implementation 'com.android.support:multidex:1.0.3'
}
apply plugin: 'com.google.gms.google-services'

使用multidex支持应该是最后的手段。默认情况下,gradle build将为APK收集大量可传递的依赖项。如中所建议的,首先尝试从项目中删除不必要的依赖项

使用命令行导航到Android项目根目录。 您可以按如下方式获得编译依赖关系树

gradlew app:dependencies --configuration debugCompileClasspath
您可以获得依赖关系树的完整列表

gradlew app:dependencies

然后从应用程序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'
   }
然后在Android Studio中选择构建>分析APK。。。 选择release/debug APK文件以查看内容。这将为您提供如下方法和引用计数


如果您将minifyEnabled与Proguard一起使用,则可能不需要启用多索引。我同意MG Developer的观点,如果可能,您应该尝试避免使用多索引。我的解决方案是仅为调试版本启用多索引。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
    }
}

对于颤振项目您也可以解决此问题

打开您的\android\app\build.gradle

您应该具备以下条件:

android {
    defaultConfig {
        ...
        minSdkVersion 16
        targetSdkVersion 28

    }

}
如果您的minSdkVersion设置为21或更高,则只需在defaultConfig中将multiDexEnabled设置为true

android {
    defaultConfig {
        ...
        minSdkVersion 16
        targetSdkVersion 28
        multiDexEnabled true 

    }

}
如果您的minSdkVersion设置为20或更低,请将multiDexEnabled true添加到defaultConfig

并定义实现

dependencies {
  implementation 'com.android.support:multidex:1.0.3'// or 2.0.1
}
最后,你应该有:

android {
    defaultConfig {
        ...
        minSdkVersion 16
        targetSdkVersion 28
        multiDexEnabled true  // added this
    }

}

dependencies {
  implementation 'com.android.support:multidex:1.0.3'
}
有关更多信息,请阅读以下内容:

当您使用依赖项时,您的方法会增加! 谷歌有一个解决方案,叫做Multidex

注意:确保最小SDK超过14。

在您的构建中。gradle:

android {
    defaultConfig {
        ...
        minSdkVersion 15 
        targetSdkVersion 28
        multiDexEnabled true
    }
    ...
}



  dependencies {
      implementation 'com.android.support:multidex:1.0.3'
    }
 def multidex_version = "2.0.1"
 implementation 'androidx.multidex:multidex:$multidex_version'
对于androidX的使用:

android {
    defaultConfig {
        ...
        minSdkVersion 15 
        targetSdkVersion 28
        multiDexEnabled true
    }
    ...
}



  dependencies {
      implementation 'com.android.support:multidex:1.0.3'
    }
 def multidex_version = "2.0.1"
 implementation 'androidx.multidex:multidex:$multidex_version'

欲了解更多信息,请
android {
    defaultConfig {
        ...
        minSdkVersion 15 
        targetSdkVersion 28
        multiDexEnabled true
    }
    ...
}



  dependencies {
      implementation 'com.android.support:multidex:1.0.3'
    }
 def multidex_version = "2.0.1"
 implementation 'androidx.multidex:multidex:$multidex_version'
dependencies {
  implementation 'com.android.support:multidex:1.0.3'
}
defaultConfig {
    minSdkVersion 16
    targetSdkVersion 28
    multiDexEnabled true  //ADD THIS LINE
}
dependencies {
  implementation 'androidx.multidex:multidex:2.0.1'
}
    defaultConfig {
        minSdkVersion 16
        targetSdkVersion 28
        multiDexEnabled true  //ADD THIS LINE
    }
 defaultConfig {
        applicationId "com.ubicacion"
        minSdkVersion rootProject.ext.minSdkVersion
        targetSdkVersion rootProject.ext.targetSdkVersion
        versionCode 1
        versionName "1.0"
        multiDexEnabled true // ✔
        missingDimensionStrategy 'react-native-camera', 'general'
    }
defaultConfig {
    applicationId "com.something"
    minSdkVersion rootProject.ext.minSdkVersion
    targetSdkVersion rootProject.ext.targetSdkVersion
    versionCode 1
    versionName "1.0"
    multiDexEnabled true --> This works for me
}
    compileSdkVersion 29

    defaultConfig {
        applicationId "com.example.appname"
        minSdkVersion 19
        targetSdkVersion 29
        versionCode 1
        versionName "1.0"
        multiDexEnabled true //addded
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }
dependencies {
implementation 'com.android.support:multidex:2.0.0' //added
}
android {
    defaultConfig {
        ...
        minSdkVersion 21 //set the minimum sdk version 21
        targetSdkVersion 29
    }
    ...
}
android {
    defaultConfig {
        ...
        
        multiDexEnabled true <------ * here
    }
    ...
}
dependencies {
//for multidex
implementation 'androidx.multidex:multidex:2.0.1'
defaultConfig {
    applicationId "com.papel.helper"
    minSdkVersion 16
    targetSdkVersion 28
    versionCode 1
    versionName "1.0"
    testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

    multiDexEnabled true
  
}
defaultConfig {
    ...
    minSdkVersion 21
 }
android {
    defaultConfig {
        ...
        multiDexEnabled true
    }
    ...
}

dependencies {
  implementation 'com.android.support:multidex:1.0.3'
}
defaultConfig {
    ...

    multiDexEnabled true
}
dependencies {
    ...

    implementation 'com.android.support:multidex:1.0.3'
}
dependencies {
    ...

    implementation 'androidx.multidex:multidex:2.0.1'
}