Gradle 2.2 NDK debugging requires release Build Variant - android

I am using the following:
Android Studio 2.2.2
Android Gradle Plugin 2.2.2
NDK r12b, r13
externalNativeBuild (ndkBuild and cmake)
I have a native JNI .so that statically links roughly two dozen other libraries. The native library exposes a Java API that is, of course, bound to the JNI. I have successfully built this library using both ndkBuild and cmake, as well as both NDK r12b and r13.
I have a test harness project that builds both an Android app module and this native library module.
According to the Android Studio 2.2 docs, using the combination of Android Studio 2.2.2, Gradle 2.2.2 and the new externalNativeBuild mechanism, native debugging is suppose to "just work." I have found, however, that native debugging only works when I set the Build Variant of the library module to "release".
I would expect a release build to be packaged with the debug symbols stripped out, so I am extremely confused. Has anyone else seen this behavior? I don't want to have to use a release variant for debugging, it makes no sense...

Related

Firebase Crashlytics with chromium (android)

Is there possible add Crashlytics to the chromium android? This is easy with projects based on gradle with Android Studio https://firebase.google.com/docs/crashlytics/get-started?authuser=0&platform=android#java . But the chromium build uses ninja build tool - without gradle and Android Studio. So I do not understand how to add Crashlytics to the chromium.
I'm pretty sure that one can build NDK projects with Gradle and Ninja, so this claim might be a misconception of what Gradle is able to do and what it isn't able to. Likely you'll have to add crashlytics.h and libcrashlytics.so for native crash reporting.
There's also an external mini-chromium module contained.
Crashpad is the chief consumer of mini_chromium.

Using external cmake executable in Android Studio

I would like my Android Studio project to use a different version of cmake than the one installed in Android Studio.
I added a variable
cmake.dir=C\:\\path\\to\\a\\different\\cmake
to my local.properties file, and this location is used for some of the compilation of my project but not all.
In the logs of my project build, I still see references to the cmake version installed in AS, and for example, in build_model.json under apps.cxx\cmake\debug\x86, I see:
"cmakeExecutable":
"C:\\Users\\myname\\AppData\\Local\\Android\\Sdk\\cmake\\3.10.2.4988404\\bin\\cmake.exe",
What other file/setting do I need to change so that AS uses exclusively an external verison of cmake for all compilation?

Android App Bundle (only) - native library failed to load

I switched to Android App Bundle (ABB) in Google Play production few months ago and released couple updates - things were fine. Last week I took Android Studio update and noticed that ONLY the ABB build fails to load one of my native library at runtime. However APK build (release) and debug build is loading the native library fine.
I was forced to deploy an APK to replace the broken ABB release in production.
I found the ABB package contains all four (arm64-v8a, armeabi-v7a, x86, x86_64) directories and all my .SO files are in there (same as in the APK package).
For further investigation, I edited the Android Studio Run Configuration to deploy 'APK from app bundle' and verified the native library is failing to load for ABB build only (other build modes are fine).
My environment: Android Studio 4.0 (latest at the moment),
'io.fabric.tools:gradle:1.28.0' (ABB worked until 1.26.1),
compileSdkVersion 28,
buildToolsVersion '28.0.3'
There is no easy way to rollback latest update. Please let me know how to fix this build issue. Appreciate your help.
Finally found the workaround to resolve this issue. The third-party library that I am using is not compliant with the recent Gradle change. Java code of the library doesn't know the right path to it's SO file when an APK is constructed from ABB on a device. Setting in the gradle.properties file works well.
According to the Gradle release note
When building an Android App Bundle, APKs generated from that app
bundle that target Android 6.0 (API level 23) or higher now include
uncompressed versions of your native libraries by default. This
optimization avoids the need for the device to make a copy of the
library and thus reduces the on-disk size of your app. If you'd rather
disable this optimization, add the following to your gradle.properties
file:
android.bundle.enableUncompressedNativeLibs = false

How to completely disable NDK support in Android Studio

We have a multi-platform project, with native support, that we are developing in Android Studio using libgdx. We have builds working for Desktop, IOS, Android, Android Wear, and HTML5.
On each of these platforms, we have a different "native" plugin that we are using: a static .a native library on IOS, a .dll on Windows, a bunch of .so files in Android, and a Javascript library on HTML5. All of these, except for the HTML5 version, are built on separate platforms so can't possibly be built by the same Android Studio NDK build.
The problem is that for each of the .java files that declare JNI routines, Android Studio 1.4.x wants to find the source files, but those source files can't possibly be compiled in the IOS project, and likewise for the PC project when running on a Mac.
The standard solution on SO is to add
sourceSets {
main {
jni.srcDirs = [] //disable automatic ndk-build
}
}
To the android{} section, but this ONLY works for the Android, Android Wear launcher projects, and NOT Desktop, IOS, HTML5, etc.
I just want Android Studio to give up on trying to compile NDK, because it can't possibly be done on non-Android projects. Other than finding a downgrade somewhere, how do I do that?
Thanks!
So, I decided that I could figure this out - and I did!
Of course, the NDK builder is just a plugin in IntelliJ, so all you have to do to disable it is to
go to your AndroidStudio installation,
find the "plugins" directory
move or delete the "android-ndk" folder
Tada! No more NDK plugin!
Correct way is to uninstall NDK using SDK manager.
go to Android Studio-> Tools -> SDK Manager
Under SDK tools tab uncheck "NDK", "CMake", "LLDB" and then apply changes. NDK components will be removed.
Downside is NDK is removed for all project. Still struggling to find a way to disable NDK for a particular project only.
If you would like to keep the NDK build for future use and not use it for specific projects just make sure to uncheck these options in the new project dialog...

Android NDK Debug Library

I have a Java Android application project that includes a so library in libs/armeabi folder.
The c++ code of this library is in a different Android NDK project and is dependent on other different library NDK projects.
Is it possible to debug the c++ code of this library while the Java Android application is running?
In order to debug the native code in .so, first you need .so that was generated with debugging mode. (e.g., NDK_DEBUG = 1)
If you don't have source code and therefore no debuggable .so, there is no way to debug.
Also, please specify your environment such as Android NDK version, IDE, etc.
Assuming you are using Eclipse, this is detailed description how to debug native applications.

Categories

Resources