code

오류: 요청한 클래스를 단일 덱스 파일에 넣을 수 없습니다.주 인덱스 목록을 제공해 보십시오.방법 : 72477 > 65536

starcafe 2023. 6. 2. 20:40
반응형

오류: 요청한 클래스를 단일 덱스 파일에 넣을 수 없습니다.주 인덱스 목록을 제공해 보십시오.방법 : 72477 > 65536

퓨전 위치 서비스를 추가하고 싶은데 오류가 표시됩니다.도와줘.

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'

그들이 당신에게 준 대답 중 어떤 것도 완전하지 않았습니다.문제는 멀티덱스에 있습니다.앱 그라들에서 라이브러리를 추가해야 합니다.

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

그런 다음 app Gradle의 defaultConfig를 추가합니다.

multiDexEnabled true

응용 프로그램이 다중 인덱스 유형이어야 합니다.매니페스트에 다음과 같이 기록해야 합니다.

android:name=".MyApplication"

"MyApplication"은 Multidex 클래스이거나 이 클래스를 확장해야 합니다.

아래 솔루션의 문제를 해결했습니다.

Gradle 빌드 파일에서 종속성을 추가합니다.

구현 'com.dll.지원:multidex:1.0.3'

그런 다음 "defaultConfig" 섹션에서 다음을 추가합니다.

multiDexEnabled true

앱이나 build.gradle

android {
    defaultConfig {
        ...
        minSdkVersion 21 <----- *here
        targetSdkVersion 26
        multiDexEnabled true <------ *here
    }
    ...
}

공식 문서에 따르면

Android 5.0 이상에 대한 멀티덱스 지원

Android 5.0(API 레벨 21) 이상에서는 ART라는 런타임을 사용하여 APK 파일에서 여러 DEX 파일 로드를 기본적으로 지원합니다. ART는 앱 설치 시 사전 컴파일을 수행하여 클래스 N.dex 파일을 검색하고 Android 장치에서 실행할 수 있도록 단일 .ot 파일로 컴파일합니다.따라서 minSdkVersion이 21 이상이면 멀티덱스 지원 라이브러리가 필요하지 않습니다.

Android 5.0 런타임에 대한 자세한 내용은 ART 및 Dalvik을 참조하십시오.

https://developer.android.com/studio/build/multidex

덱스 파일이란 무엇입니까?Android 앱(APK) 파일에는 앱을 실행하는 데 사용된 컴파일된 코드가 포함된 Dalvik 실행 파일(DEX) 형식의 실행 바이트 코드 파일이 포함되어 있습니다.

이 예외의 이유:DEX 사양은 Android 프레임워크 메서드, 라이브러리 메서드 및 자체 코드의 메서드를 포함하여 단일 DEX 파일 내에서 참조할 수 있는 총 메서드 수를 65,536개(64K 참조 제한)로 제한합니다.

01단계.다음과 같이 종속성을 추가합니다.

Androidx가 아닌 사용자의 경우

dependencies {
  implementation 'com.android.support:multidex:1.0.3'
}
defaultConfig {
    minSdkVersion 16
    targetSdkVersion 28
    multiDexEnabled true  //ADD THIS LINE
}

Androidx 사용자의 경우

dependencies {
  implementation 'androidx.multidex:multidex:2.0.1'
}
    defaultConfig {
        minSdkVersion 16
        targetSdkVersion 28
        multiDexEnabled true  //ADD THIS LINE
    }

02단계:

이러한 동기화 프로젝트를 추가한 후 프로젝트를 실행하기 전에 실행 전에 프로젝트를 빌드해야 합니다.그렇지 않으면 예외가 발생합니다.

이것을 따라 하시면 됩니다.

Android 5.0(API 레벨 21) 이전 버전의 플랫폼은 앱 코드 실행을 위해 Dalvik 런타임을 사용합니다.기본적으로 Dalvik은 APK당 단일 class.dex 바이트코드 파일로 앱을 제한합니다.이 제한을 피하기 위해 프로젝트에 멀티덱스 지원 라이브러리를 추가할 수 있습니다.

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

minSdkVersion이 21 이상으로 설정된 경우 다음과 같이 모듈 수준의 build.gradle 파일에서 multiDexEnabled를 true로 설정하기만 하면 됩니다.

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

당신이 의존성을 사용하고 있어서 당신의 방법이 증가했을 때! 구글은 그것에 대한 해결책을 가지고 있습니다. 그것은 멀티덱스라고 불립니다!

참고: min SDK는 14 이상이어야 합니다.

당신의 체격에.gradle:

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



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

AndroidX용:

 def multidex_version = "2.0.1"
 implementation 'androidx.multidex:multidex:$multidex_version'

자세한 내용은 원본 링크를 참조하십시오.

https://developer.android.com/studio/build/multidex

안녕 문제는 이것을 제거하는 것입니다.

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

왜요?

참고: 복합 플레이 서비스 대상을 사용하지 마십시오.그것은 수십 개의 라이브러리를 가져와 애플리케이션을 부풀립니다.대신 앱에서 사용하는 특정 Google Play 서비스 API만 지정합니다.

필요한 것을 사용하십시오.https://developers.google.com/android/guides/setup

위치 서비스에 대해 좋아요

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

클라우드 메시징의 경우

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

Flutter 프로젝트에서 아래 솔루션을 사용했습니다.

을 엽니다.yourproject/app/build.gradle다음 행을 추가합니다.

android {
    ...

    defaultConfig {
        ...
        
        minSdkVersion 21
        multiDexEnabled true
    }
}

그리고나서

dependencies {
    ...

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

으로 AndroidX대신 이것을 원할 것입니다.

dependencies {
    ...

    implementation 'androidx.multidex:multidex:2.0.1'
}

이 해결책은 저에게 효과가 있었습니다.이 질문을 해주셔서 감사합니다.

DEBUG APK를 구축하는 경우 다음을 추가하면 됩니다.

debug {
            multiDexEnabled true
        }

東京의 buildTypes

그리고 RELEASE APK를 구축하는 경우 추가multiDexEnabled true릴리스 블록에서 다음과 같이...

release {
                ...
                multiDexEnabled true
                ...
        }

플래터 프로젝트의 경우에도 이 문제를 해결할 수 있습니다.

\build\app\build.gradle을 엽니다.

다음이 있어야 합니다.

android {
    defaultConfig {
        ...
        minSdkVersion 16
        targetSdkVersion 28

    }

}

minSdkVersion이 21 이상으로 설정된 경우 기본 구성에서 multiDexEnabled를 true로 설정하기만 하면 됩니다.이것처럼.

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

    }

}

minSdkVersion이 20 이하로 설정된 경우 multiDexEnabled true를 기본 Config에 추가합니다.

구현 정의

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'
}

자세한 내용은 https://developer.android.com/studio/build/multidex 을 참조하십시오.

저도 같은 문제를 이렇게 풀었으니 간단한 2단계만 해주시면 됩니다.저는 AndroidX 사용자이므로 먼저 프로젝트 독립성 섹션의 build.gradle 파일에 이 종속성을 구현합니다.

implementation 'androidx.multidex:multidex:2.0.1'

dependencies {
//for multidex
implementation 'androidx.multidex:multidex:2.0.1'

}

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
  
}

이제 프로젝트를 다시 빌드하고 실행합니다. :)

다음을 수행합니다.

빌드.그래들

(module:app)


android {
            ....
      defaultConfig {
              multiDexEnabled true // enable mun
      }
}

그리고 아래의 의존성을 추가합니다.build.gradle file (앱 레벨 파일)

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

는 제 이 .
나는 방금 최소 SDK 버전을 21로 설정했고 그것이 내 문제를 해결했습니다.

android {
    defaultConfig {
        ...
        minSdkVersion 21 //set the minimum sdk version 21
        targetSdkVersion 29
    }
    ...
}

minSdkVersion이 21 이상인 경우 멀티덱스가 기본적으로 사용되며 멀티덱스 지원 라이브러리가 필요하지 않습니다.멀티덱스에 대해 자세히 알아보려면 https://developer.android.com/studio/build/multidex.html

Gradle 빌드 파일에서 종속성을 추가합니다.

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

또는

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

또는

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

그런 다음 "defaultConfig" 섹션에서 다음을 추가합니다.

multiDexEnabled true

대상 아래 SdkVersion

minSdkVersion 17
targetSdkVersion 27
multiDexEnabled true

이 오류가 발생할 경우

오류: 확인하지 못했습니다. 다중 설치 파일 열기

Gradle을 3.0.1로 변경해야 합니다.

classpath 'com.android.tools.build:gradle:3.0.1'

그리고 gradle-wrapper.properties 파일에 다음 코드를 넣습니다.

분배URL = https://services.gradle.org/distributions/gradle-4.1-all.zip https://services.gradle.org/distributions/gradle-4.1-all.zip

마침내.

프로젝트에 클래스 응용 프로그램을 추가하고 MultiDex 응용 프로그램에서 확장된 Android Manifest에 소개합니다.

public class App extends MultiDexApplication {

    @Override
    public void onCreate( ) {
        super.onCreate( );
    }
}

프로젝트를 먼저 실행하여 오류를 생성한 다음 프로젝트를 치료합니다.

마지막으로, 프로젝트를 다시 시작하고 즐기십시오.

앱 또는 모듈의 build.gradle에 이 코드를 추가하기만 하면 됩니다.

android {
    defaultConfig {
        ...
        
        multiDexEnabled true <------ * here
    }
    ...
}
multiDexEnabled true

앱 defaultConfig {}에 이 항목을 추가해 보십시오.이것은 문제를 해결하는 데 도움이 됩니다.

이것은 Kotlin 또는 Java 프로젝트에서 작업을 수행할 것입니다.

1단계 - Gradle 스크립트에서 build.gradle(모듈: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"
    }

3단계 - 다중 지수 종속성 추가

dependencies {
implementation 'com.android.support:multidex:2.0.0' //added
}

마지막으로 프로젝트를 동기화합니다.맛있게 드세요!

Proguard와 함께 minifyEnabled를 사용하는 경우 다중 인덱스를 사용할 필요가 없습니다.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 덱스 파일은 65536개의 메서드를 허용합니다.

우선, 모든 구글 플레이 서비스 API가 필요하지 않고 위치만 필요하다면 교체하세요.

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

와 함께

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

페이지에서 이를 방지하는 방법이나 추가 허용이 필요한 경우 https://developer.android.com/studio/build/multidex.html 을 참조할 수 있습니다.

왜 그런지 요, , 이 나는왜그지모다발, 아도내코것다이, ▁class▁▁a▁i▁i합다니만▁have야▁kot▁create,어▁in▁to들▁this나▁to▁but▁maybe▁i▁why▁fix▁error클하를lin는▁it스▁no래▁idea확는▁finally▁have▁because되▁develop장위마▁is오고이내나지를MultiDexApplication다음과 같이:

class MyApplication : MultiDexApplication() {
}

그리고 내 안에서Manifest.xml설정해야 합니다.

<application
        ...
        android:name=".MyApplication">

누구도 혼란스럽게 하지 않기 위해, 저는 또한 다음과 같이 합니다.

multiDexEnabled true
implementation 'com.android.support:multidex:1.0.3'

Androidx의 경우, 이것은 저에게도 효과가 있습니다.

implementation 'androidx.multidex:multidex:2.0.0'

...

<application android:name="android.support.multidex.MultiDexApplication">

나에게는 통하지 않습니다.

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'
    }
  1. 앱 폴더의 build.grade로 이동합니다.
  2. minSdkVersion을 21로 설정

앱을 저장하고 실행하십시오. 지금 덱스 오류 없이 실행됩니다.

File > Project Structure > App > Flavors에서 Minimum SDK Version을 21로 설정하기만 하면 되었습니다.

는 이 두 번 SDK,인 SDK: appgradle: appgradle: appgradle에 한 . SDK가 20 이상이면, 한 줄만 추가하십시오.defaultconfig { multiDexEnabled true }

그렇지 않으면 당신의 목표가SDK가 20 미만입니다. defaultConfig에 라인을 추가하고 종속성도 추가합니다.

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

자세한 내용은 이 링크를 참조하십시오.

https://developer.android.com/studio/build/multidex#mdex-gradle

멀티덱스 지원을 사용하는 것이 최후의 수단이 되어야 합니다.기본적으로 Gradle 빌드는 APK에 대한 과도 종속성을 많이 수집합니다.Google 개발자 문서에서 권장하는 대로 먼저 프로젝트에서 불필요한 종속성을 제거합니다.

명령줄을 사용하여 Android Projects Root로 이동합니다.컴파일 종속성 트리를 다음과 같이 가져올 수 있습니다.

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에서 Build > Analyze APK...를 선택합니다.내용을 보려면 릴리스/디버깅 APK 파일을 선택합니다.이렇게 하면 다음과 같은 방법과 참조 수가 표시됩니다.

APK 분석

빌드 중: 앱

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'
android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "com.dev.khamsat"
        minSdkVersion 16
        targetSdkVersion 28
        versionCode 1
        versionName "2.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        multiDexEnabled true
    }

이 오류는 앱 Gradle 파일에 있는 클래스 종속성의 수에 의해 발생합니다.클래스가 72,400을 초과하는 경우 파일 인덱싱을 보다 효율적으로 처리하기 위한 솔루션으로 멀티덱스를 사용할 수 있습니다.자세한 내용은 여기를 참조하십시오. https://developer.android.com/studio/build/multidex

두 시간 동안 고통을 겪은 후에 해결책을 찾았습니다.

파일 경로: Android/build.gradle

나를 위해 일했습니다.

defaultConfig {
    applicationId "com.something"
    minSdkVersion rootProject.ext.minSdkVersion
    targetSdkVersion rootProject.ext.targetSdkVersion
    versionCode 1
    versionName "1.0"
    multiDexEnabled true --> This works for me
}

minSdkVersion이 21 이상으로 설정되어 있으면 멀티덱스가 기본적으로 활성화되므로 멀티덱스 지원 라이브러리가 필요하지 않습니다. - 참조: https://developer.android.com/studio/build/multidex#mdex-gradle

제가 답변에 늦었다는 것은 알지만, 이 문제는 대부분 하나의 의존성 때문에 발생한다고 확신합니다.'com.google.android.gms:play-services'문제 및 해결 방법에 대한 이해를 높이기 위해 전체 답변을 읽어보십시오.

제 경우에는, 저는'com.google.android.gms:play-services-location:21.0.1'제가 이 답변을 쓸 때쯤이면 최신 버전입니다.메서드 수가 너무 많습니다.제가 이걸 사용한 유일한 동기는 사용자장치에서 위치를 가져오는 것입니다.Google은 다음을 사용할 것을 권장합니다.play-services-location위치를 가져오는 용도로만 사용할 수 있으므로 작업을 완료하기 위한 이러한 종속성을 대체하고 싶지 않았습니다.그래서 수많은 구글 검색을 해본 결과,

버전을 다운그레이드할 수 있습니다.

이전의 안정적인 버전으로 작업을 완료할 수 있습니다.그리고 저의 경우, 저에게 가장 적합한 버전이 나왔습니다.17.1.0따라서 사용할 사용 사례가 있는 경우에만 이 특정 버전을 사용하는 것이 좋습니다.play-services-location내 것과 똑같습니다.

변경사항을 수행

implementation 'com.google.android.gms:play-services-location:21.0.1'

로.

implementation 'com.google.android.gms:play-services-location:17.1.0'

그럼에도 불구하고 코드에는 항상 멀티덱스를 사용할 수 있는 옵션이 있지만, 그것이 IMO 문제를 해결하는 가장 비효율적인 방법입니다.

의존성의 근본 원인이 큰 메서드 수만큼 덱스 파일 크기를 최대화하는 것이라면, 그 의존성을 조정하거나 대체해야 한다고 생각합니다.

언급URL : https://stackoverflow.com/questions/48249633/errorcannot-fit-requested-classes-in-a-single-dex-file-try-supplying-a-main-dex

반응형