티스토리 뷰

반응형

Stack Overflow에 자주 검색, 등록되는 문제들과 제가 개발 중 찾아 본 문제들 중에서 나중에도 찾아 볼 것 같은 문제들을 정리하고 있습니다.

Stack Overflow에서 가장 먼저 확인하게 되는 가장 높은 점수를 받은 Solution과 현 시점에 도움이 될 수 있는 가장 최근에 업데이트(최소 점수 확보)된 Solution을 각각 정리하였습니다.

 

아래 word cloud를 통해 이번 포스팅의 주요 키워드를 미리 확인하세요.

More than one file was found with OS independent path 'META-INF/LICENSE'

OS에 독립적인 경로 'META-INF/LICENSE'에서 파일이 하나 이상 발견되었습니다.

 문제 내용 

When I build my app, I get the following error:

앱을 빌드하려고 하면 다음과 같은 오류가 발생합니다:

 

Error: Execution failed for task ':app:transformResourcesWithMergeJavaResForDebug'. More than one file was found with OS independent path 'META-INF/LICENSE'

오류: ': app : transformResourcesWithMergeJavaResForDebug' 작업을 실행하는 동안 오류가 발생했습니다. 'META-INF / LICENSE' OS 독립적인 경로에서 하나 이상의 파일이 발견되었습니다.

 

This is my build.gradle file:

이것은 제 build.gradle 파일입니다.
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
android {
    compileSdkVersion 25
    buildToolsVersion "25.0.2"
    defaultConfig {
        applicationId "cn.sz.cyrus.kotlintest"
        minSdkVersion 14
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

        javaCompileOptions{
            annotationProcessorOptions{
                includeCompileClasspath = true
            }
        }
        multiDexEnabled true
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    packagingOptions {
 /*       exclude 'META-INF/DEPENDENCIES'
        exclude 'META-INF/NOTICE'
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/NOTICE.txt'*/
    }
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
    compile "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version"
    compile 'com.android.support:appcompat-v7:25.3.1'
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:design:25.3.1'
    compile 'com.android.support.constraint:constraint-layout:1.0.2'
    debugCompile 'com.squareup.leakcanary:leakcanary-android:1.5.1'
    releaseCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.5.1'
    testCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.5.1'
    compile 'com.github.GrenderG:Toasty:1.2.5'
    compile 'com.orhanobut:logger:1.15'

    compile 'io.reactivex.rxjava2:rxandroid:2.0.1'
    compile 'com.umeng.analytics:analytics:latest.integration'
    compile 'ai.api:libai:1.4.8'
    compile 'ai.api:sdk:2.0.5@aar'
// api.ai SDK dependencies
    compile 'com.google.code.gson:gson:2.8.0'
    compile 'commons-io:commons-io:2.4'
    compile 'com.android.support:multidex:1.0.1'
}

 

When I add this code to my build.gradle file,

제 build.gradle 파일에 이 코드를 추가하면,
  packagingOptions {
            exclude 'META-INF/DEPENDENCIES'
            exclude 'META-INF/NOTICE'
            exclude 'META-INF/LICENSE'
            exclude 'META-INF/LICENSE.txt'
            exclude 'META-INF/NOTICE.txt'
        }

 

This error would be solved, but another problem will happen. Like this:

이 오류는 해결될 수 있지만, 다른 문제가 발생할 수 있습니다. 다음과 같은 문제가 발생합니다:
java.lang.NoClassDefFoundError: com.squareup.leakcanary.internal.HeapAnalyzerService
at com.squareup.leakcanary.LeakCanary.isInAnalyzerProcess(LeakCanary.java:145)
at cn.sz.cyrus.wemz.TestApplication.onCreate(TestApplication.kt:32)

 

Who has ideas how to solve this?

이것에 대한 해결 아이디어가 있는 사람은 누구나 제안해 주세요.

 

 

 

 높은 점수를 받은 Solution 

You can add this in yourProject/app/build.gradle inside android{}. The exclude function adds the named resource to the list of resources that are not packaged in the APK.

이 코드를 `yourProject/app/build.gradle` 파일의 `android{}` 안에 추가할 수 있습니다. `exclude` 함수는 APK에 포함되지 않아야 하는 리소스의 목록에 지정된 리소스를 추가합니다.
android {      
      packagingOptions {
        exclude("META-INF/DEPENDENCIES")
        exclude("META-INF/LICENSE")
        exclude("META-INF/LICENSE.txt")
        exclude("META-INF/license.txt")
        exclude("META-INF/NOTICE")
        exclude("META-INF/NOTICE.txt")
        exclude("META-INF/notice.txt")
        exclude("META-INF/ASL2.0")
        exclude("META-INF/*.kotlin_module") 
      }          
}

 

The exclude function is deprecated in 7.0.2 and you should use something similar to this:

`exclude` 함수는 7.0.2에서 더 이상 사용되지 않으며, 다음과 유사한 것을 사용해야합니다.
android {
   ...
   packagingOptions {
       resources.excludes.add("META-INF/*")
   }
}

 

 

 가장 최근 달린 Solution 

For Gradle 7.2 and later Add in-app Gradle file

Gradle 7.2 이상 버전인 경우, 앱 내 Gradle 파일에 다음을 추가합니다.
android {
  
   packagingOptions {
       resources.excludes.add("META-INF/*")
   }


}

 

 

출처 : https://stackoverflow.com/questions/44342455/more-than-one-file-was-found-with-os-independent-path-meta-inf-license

반응형
댓글
공지사항
최근에 올라온 글