After update android studio and plugins, new built apk meets puzzling native problem when launch, I found armeabi/armeabi-v7a so files compressed from 200KB to 10KB. While
Update: Use the official doNotStrip
option, https://google.github.io/android-gradle-dsl/current/com.android.build.gradle.internal.dsl.PackagingOptions.html
Thanks to Wayne Cai's answer.
In addition, to disable strip on all so files, you can add following to your build.gradle
:
packagingOptions{
doNotStrip "**/*.so"
}
Old answer:
I had the same problem, and can't find any official method to disable this auto strip feature on the internet.
Fortunately, I finally got this work around in build.gradle:
applicationVariants.all { variant ->
def copyUnstripedJniLibTask = tasks.create(name: "copyUnstripedJniLibFor${variant.name.capitalize()}") << {
def destDirRoot = new File(projectDir, "build/intermediates/transforms/stripDebugSymbol/${variant.dirName}/folders/")
if (!destDirRoot.isDirectory()) return
// the folder contains final so files is something like "stripDebugSymbol/variantName/debug/folders/2000/1f/main/lib/",
// I don't know how to generate the "2000/1f" part, so I have to search for it.
// If you got better idea, please comment.
def list = FileUtils.listFiles(destDirRoot, FileFilterUtils.suffixFileFilter("so"), FileFilterUtils.trueFileFilter());
if (list.size() <= 0) return
def destDir = list[0].getParentFile().getParentFile()
def srcDir = new File(destDir.getAbsolutePath().replace("stripDebugSymbol", "mergeJniLibs"))
println "Copying unstriped jni libs ..."
println " from ${srcDir}"
println " to ${destDir}"
// Copy the unstriped so files to overwrite the striped ones.
FileUtils.copyDirectory(srcDir, destDir)
}
def transformNativeLibsTask = project.tasks.findByName("transformNative_libsWithStripDebugSymbolFor${variant.name.capitalize()}")
if (transformNativeLibsTask) {
transformNativeLibsTask.finalizedBy(copyUnstripedJniLibTask)
}
}
Hope this will solve your problem.