美文网首页
Android Gradle中packagingOptions选

Android Gradle中packagingOptions选

作者: 老米拉 | 来源:发表于2020-10-02 17:18 被阅读0次
    * What went wrong:
    Execution failed for task ':app:transformNativeLibsWithStripDebugSymbolForDebug'.
    
    > A problem occurred starting process 'command 'D:\Users\sky\AppData\Local\Android\Sdk\ndk-bundle\toolchains\mips64el-linux-android-4.9\prebuilt\windows-x86_64\bin\mips64el-linux-android-strip''
    Error:com.android.builder.merge.DuplicateRelativeFileException:
    More than one file was found with OS independent path 'META-INF/DEPENDENCIES'
    Execution failed for task ':app:transformNativeLibsWithMergeJniLibsForRelease'.
    
    > More than one file was found with OS independent path 'lib/armeabi/libJniTest.so'
    

    类似于这种编译打包时,找不到工具链的。由于NDK开发工具的包的问题导致如果不需要对应的架构可以直接设置

      packagingOptions {
            doNotStrip '*/mips/*.so'
            doNotStrip '*/mips64/*.so'
            doNotStrip '*/x86_64/*.so'
        }
    

    这样就剔除了mips,mips64,x86_64架构,也就用不到对应的架构的工具链了。问题自然而解,如果必须要对应的架构那就下载完整的NDK开发工具包。

    当然想打包时文件重复的问题也可以使用这个选项,常见的就是引入的so库重

    • exclude 在打包时移除项目中的相关文件,不打入apk文件中
    packagingOptions {
        exclude 'META-INF/ASL2.0'
        exclude 'META-INF/DEPENDENCIES.txt'
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/NOTICE.txt'
        exclude 'META-INF/NOTICE'
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/DEPENDENCIES'
        exclude 'META-INF/notice.txt'
        exclude 'META-INF/license.txt'
        exclude 'META-INF/dependencies.txt'
        exclude 'META-INF/LGPL2.1'
        exclude 'META-INF/services/javax.annotation.processing.Processor'exclude 'META-INF/rxjava.properties'
    }
    
    • pickFirst 当有多个匹配项的时候匹配到第一个就可以了
     packagingOptions {
            pickFirst "lib/armeabi-v7a/libavdevice.so"
            pickFirst "lib/armeabi-v7a/libavcodec.so"
            pickFirst "lib/armeabi-v7a/libavfilter.so"
            pickFirst "lib/armeabi-v7a/libavformat.so"
            pickFirst "lib/armeabi-v7a/libavutil.so"
            pickFirst "lib/armeabi-v7a/libswresample.so"
            pickFirst "lib/armeabi-v7a/libswscale.so"
            pickFirst "lib/armeabi-v7a/libpostproc.so"
        }
    

    相关文章

      网友评论

          本文标题:Android Gradle中packagingOptions选

          本文链接:https://www.haomeiwen.com/subject/bbwbuktx.html