0

Project is made in Android Studio. It's Java+C through NDK. Android Studio is generating *.so files. How to change it to *.a files?

.so files are made by gradle NDK. (without .mk files)

Is there a method/flag in gradle to ask for a static library (.a file)? (I need to share that .a and not .so)

Gradle file:

apply plugin: 'android'
android {
compileSdkVersion 19
buildToolsVersion '19.1'
defaultConfig {
    minSdkVersion 10
    targetSdkVersion 19
    versionCode 1
    versionName '1.0'

    ndk
    {
        moduleName "mylib"
        ldLibs  "m", "log", "android", "jnigraphics"
    }
}
// This actual the app version code. Our given range is [0, 99999]
defaultConfig.versionCode = 3

// 2 dimensions of flavors. API is more important than ABI.
flavorDimensions "abi"

productFlavors {
    x86 {
        dimension "abi"
        ndk {
            abiFilter "x86"
        }
        // this is the flavor part of the version code.
        // It must be higher than the arm one for devices supporting
        // both, as x86 is preferred.
        versionCode = 3
    }
    arm {
        dimension "abi"
        ndk {
            abiFilter "armeabi-v7a"
        }
        versionCode = 2
    }
    mips {
        dimension "abi"
        ndk {
            abiFilter "mips"
        }
        versionCode = 1
    }
    fat {
        dimension "abi"
        // fat binary, lowest version code to be
        // the last option
        versionCode = 0
    }
}

// make per-variant version code
applicationVariants.all { variant ->
    // get the version code of each flavor
    def abiVersion = variant.productFlavors.get(0).versionCode

    // set the composite code
    variant.mergedFlavor.versionCode = abiVersion * 100000 + defaultConfig.versionCode
}

buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
    }
}
}

dependencies {
compile 'com.android.support:appcompat-v7:19.+'
compile fileTree(include: ['*.jar'], dir: 'libs')    
}
Edgehog.net
  • 356
  • 1
  • 7
  • 1
    No, this is impossible. But please explain what problem you are trying to solve? What's wrong with adding an **Android.mk** file? You can even generate such file from your **build.gradle** on the fly. – Alex Cohn Dec 02 '15 at 08:31
  • I tried adding it. It didn't work. I used that autogenerated Android.mk. I added line in gradle: 'sourceSets.main.jni.srcDirs = []' . And added Aplication.mk that I had to make myself (it wasnt autogenerated). Now app crashes on LoadLibrary. **Application.mk**: APP_OPTIM := release APP_ABI := all APP_ABI := all APP_STL := stlport_static APP_PLATFORM := android-19 APP_BUILD_SCRIPT := makefiles/Android.mk – Edgehog.net Dec 03 '15 at 04:01
  • "Now app crashes on LoadLibrary" - that's expected! JNI cannot work with static libraries. – Alex Cohn Dec 03 '15 at 07:15
  • it crashed regardless of include$(). In both cases app does not compile C code. (no .so/.a files in build folder). I assume it has something to do with ndk-build – Edgehog.net Dec 03 '15 at 09:10
  • You should explicitly instruct gradle to call **ndk-build**. See [how I do this](http://stackoverflow.com/a/32640823/192373) to resolve a slightly different problem. – Alex Cohn Dec 03 '15 at 09:54
  • 1
    Thanks. I managed to do it. And also I looked into experimental plugin and found that it has _android.sources.main.jni.dependencies { **linkage = "static"** }_ – Edgehog.net Dec 07 '15 at 06:17
  • Thanks for sharing, that's a cool addition. This *dependencies* was added with **0.4.0**. – Alex Cohn Dec 07 '15 at 07:53

0 Answers0