Why Does Gradle Build My Module in Release Mode When the App Is in Debug

Why does Gradle build my module in Release mode when the app is in Debug

In the "Build Variants" panel window on the left, you should see both of your modules, and next to them the current "active" variants. For instance

app          debug
custom_lib debug

When calling Build > Make Project we are building every modules in the project in their current variant.

However, due to a current Gradle limitation (https://code.google.com/p/android/issues/detail?id=52962), building app in debug will require building the release variant of custom_lib, and so you end up building both.

I would recommend to not use Make Project but instead use the option below that says Make Module app. This option will change from app to lib based on the current selection in the Project panel or based on the current editor, and will always do only what's needed to build the current module.

(Looking into this, we noticed that there isn't a shortcut for it, so we're adding one).

I want to use different library in debug and release mode In Android

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.

Flutter : can't build android in debug or release

I faced this issue and resolved it by following the below steps.

  1. Update in File (gradle-wrapper.properties) with distributionUrl=https\://services.gradle.org/distributions/gradle-6.7-all.zip

  2. Update JDK to 11 in Project StructureSample Image

Workaround to link a shared library in debug mode with Android Studio (v2+)

For this to work, the twobuild.gradle files must not be modified at the same time before syncing once for all. I had to follow the following steps:

  • Step 1: modify the lib's build.gradle, exactly as Kane said:

    // "android" section:
    defaultPublishConfig 'release'
    publishNonDefault true
    productFlavors {
    library {
    /* This strange empty flavour is actually needed
    for the step 3 to be successful */
    }
    }
  • Step 2: clean/rebuild

  • Step 3: modify the app's build.gradle, also as Kane said:

    dependencies {
    debugCompile project(path: ':custom_lib', configuration: "libraryDebug")
    releaseCompile project(path: ':custom_lib', configuration: "libraryRelease")
    }
  • Step 4: Gradle sync.

So it was just a matter of changing the library first, and then cleaning before modifying the app.

I checked the APK produced by the debug and release build modes, and each of them contains the proper variant of the lib, unlike before applying this workaround, so it does work (thanks Kane !).



Related Topics



Leave a reply



Submit