0

debug:

jniLibs/armeabi/a.so

release:

jniLibs/armeabi/b.so

I want to use a.so in debug mode and b.so in release mode, how can I do in build.gradle or other?

The .so library is third library, placed in jniLibs/armeabi/. I don't know the specific call timing, so I cannot use System.loadLibrary() method.

Thanks!

shizhen
  • 12,251
  • 9
  • 52
  • 88
Ven Shine
  • 8,739
  • 2
  • 9
  • 24

3 Answers3

4

Here is another alternative. Add your debug SO file like so:

app/src/debug/jniLibs/armeabi/<yourdebug>.so

Retain your release SO file in the main sourceset like so:

app/src/main/jniLibs/armeabi/<yourrelease>.so

It is important that <yourdebug>.so and <yourrelease>.so have the same filename for this to work.

Cheers!

user1506104
  • 6,554
  • 4
  • 71
  • 89
  • This deserves all the upvotes! This seems to be the default expected path as well, no need to modify paths in the build.gradle – jjv360 Mar 27 '20 at 10:35
2

Historically the NDK supported ARMv5 (armeabi), and 32-bit and 64-bit MIPS, but support for these ABIs was removed in NDK r17.

Also, note below anouncement from Google:

Starting August 1, 2019, your apps published on Google Play will need to support 64-bit architectures. 64-bit CPUs deliver faster, richer experiences for your users. Adding a 64-bit version of your app provides performance improvements, makes way for future innovation, and sets you up for devices with 64-bit-only hardware.

So, you should stop using the legacy armeabi for your Android applications. And, start to use the 64-bit ABIs. See https://developer.android.com/distribute/best-practices/develop/64-bit and https://developer.android.com/ndk/guides/abis for more details.

For how to organise the debug and release build type, theoretically, you can put the mynative-lib.so anywhere you like, e.g. they are under /Users/<your-usr-name>/android/jniLibs. But, I would like recommend you to arrange your debug and release build types as below (per each supported ABI):

jniLibs
├── debug
│    ├── arm64-v8a
│    │   └── mynative-lib.so
│    ├── armeabi-v7a
│    │   └── mynative-lib.so
│    ├── x86
│    │   └── mynative-lib.so
│    └── x86_64
│        └── mynative-lib.so
└── release
     ├── arm64-v8a
     │   └── mynative-lib.so
     ├── armeabi-v7a
     │   └── mynative-lib.so
     ├── x86
     │   └── mynative-lib.so
     └── x86_64
         └── mynative-lib.so

Then configure your app/build.gradle file for it to point to the correct build types, i.e.

android {
    ...
    sourceSets {
        main {
            // put your jni libs that do not distinguish debug and release.
            jniLibs.srcDirs += "/Users/<your-usr-name>/android/jniLibs"]
        }
        debug {
            // put your debug version jni libs.
            jniLibs.srcDirs += "/Users/<your-usr-name>/android/jniLibs/debug"]
        }
        release {
            // put your release version jni libs.
            jniLibs.srcDirs += "/Users/<your-usr-name>/android/jniLibs/release"]
        }
    }
    ...
}

NOTE: Replace /Users/<your-usr-name>/android/jniLibs with your own correct path.

shizhen
  • 12,251
  • 9
  • 52
  • 88
1

If you are using System.loadLibrary() to load your SO files, do this:

public final static boolean IS_DEBUG = BuildConfig.BUILD_TYPE.equalsIgnoreCase("debug");

static {
    if(IS_DEBUG) {
        System.loadLibrary("yourdebugso");
    }
    else {
        System.loadLibrary("yourreleaseso");
    }
}
user1506104
  • 6,554
  • 4
  • 71
  • 89
  • The so library is third library, placed in jniLibs/armeabi/. I don't know the specific call timing, so I cannot use System.loadLibrary method. – Ven Shine Aug 26 '19 at 08:28
  • I added an alternative answer. I am not removing this original answer as this is another way to load different SO depending on build type. – user1506104 Aug 26 '19 at 08:38