“trouble writing output: Too many field references: 70185; max is 65536. You may try using --multi-dex option.” when building Android project

后端 未结 1 1166
悲哀的现实
悲哀的现实 2021-01-05 09:54

I hit this error and found no hits for the error message, so I thought I\'d share the solution I came up with to save anyone else facing the problem repeating my work.

相关标签:
1条回答
  • 2021-01-05 10:43

    The solution was to change the package in the AndroidManifest to match the main application's package.

    A manifest like this:

    <manifest package="com.example.testlibrary" ...
    

    resulted in 6k+ fields and build failure. Changing it to match the main application's package

    <manifest package="com.example.mainapplication" ...
    

    resulted in the project building successfully.

    Note that only the package in the manifest is changing, I did not make any changes to the library's Java source or its layout (the Java package was still com.example.testlibrary with directory structure to match).

    I hypothesize that the different package name is causing all the Android fields to be included again under that package. All the packages in the error listing with 6k+ fields had a different package name than the main application.

    I also (later, grr), found this blog post which details the same problem and the eventual same solution.

    0 讨论(0)
提交回复
热议问题