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
There's an undocumented method 'doNotStrip' in packagingOptions, just add following lines in your build.gradle
packagingOptions{
doNotStrip "*/armeabi/*.so"
doNotStrip "*/armeabi-v7a/*.so"
doNotStrip "*/x86/*.so"
}
update: it's in 2.3 document.
I had the same problem and what worked for me was to reset global Android studio settings as well as project specific. To do so I just done those steps:
Remove ~/.AndroidStudio2.2/
(on Linux), c:\user\yourname\.AndroidStudio2.2
(on Windows)
Do not import any settings when starting Android studio.
Probably not the most elegant way to solve this, but it works for me.
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.
Here's my variation of @recih's answer which works with the experimental plugin:
tasks.whenTaskAdded { task ->
if (task.name.startsWith('transformNative_libsWithStripDebugSymbolFor')) {
task.finalizedBy copyUnstripedJniLibTask
}
}
task copyUnstripedJniLibTask() << {
def destDirRoot = new File(projectDir, "build/intermediates/transforms/stripDebugSymbol/unprotected/debug/folders/")
if (!destDirRoot.isDirectory()) return
def destDir = destDirRoot
def srcDir = new File(destDirRoot.getAbsolutePath().replace("stripDebugSymbol", "mergeJniLibs"))
println "Copying unstriped jni libs ..."
println " from ${srcDir}"
println " to ${destDir}"
// Copy the unstripped so files to overwrite the striped ones.
FileUtils.copyDirectory(srcDir, destDir)
}