NDK support in AndroidStudio and choosing between Android Studio and Eclipse

后端 未结 1 731
粉色の甜心
粉色の甜心 2021-01-07 12:20

I got to a \'race condition\' choosing between Android studio and Eclipse:

  1. My project needs some C++ code to be linked with my app. Currently NDK is not support
相关标签:
1条回答
  • 2021-01-07 12:35

    Currently it's quite unknown how to even just link your pre-compiled .so libraries to a project.

    Not true. In the past you would zip them, rename the archive to jar and include it in your project. Now you add ABI specific versions to <project>/<module>/src/main/jniLibs/<abi> directory (provided you didn't alter your sourcesets).

    jniLibs directory structure

    This has one major advantage. You can split the resulting .apk into several based on ABI each including only its specific native libraries. The following code sample will ensure you get multiple .apks based on ABI, each will have a different versionCode as required looking like this: Axxxxxx where A is ABI code and you get 6 digits for your original version code. The sample code is supposed to be used in an application module. Native libraries will be picked from all app's dependencies automatically.

    android {
        //...
    
        splits {
            abi {
                enable true
                reset()
                include 'x86', 'armeabi-v7a', 'armeabi' // specify abis you want
                universalApk true // if you want a composite apk as well
            }
        }
        project.ext.versionCodes = [ // keep this as is
                'armeabi':1,
                'armeabi-v7a':2,
                'arm64-v8a':3,
                'mips':5,
                'mips64':6,
                'x86':8,
                'x86_64':9
        ]
        android.applicationVariants.all { variant ->
            // assign different version code for each output
            variant.outputs.each { output ->
                // keep this on one line - groovy doesn't need semicolons, the value might not be complete then
                output.versionCodeOverride = project.ext.versionCodes.get(output.getFilter(com.android.build.OutputFile.ABI), 0) * 1000000 + android.defaultConfig.versionCode
            }
        }
    }
    

    The above example is working well within my project.

    Not to talk about compiling...

    Considering I spent some hours trying to convert a non-AS native library project to an AS one and failed, I'd suggest that if you have already developed native project, keep it outside of AS and build it as .sos.

    I will look into this and update the answer once I find something useful. However I already found one of your original sources quite interesting (http://www.shaneenishry.com/blog/2014/08/17/ndk-with-android-studio/). The basic premise is that you replace Android.mk, Core.mk and Core2.mk with instructions in the build.gradle file. According to http://ph0b.com/android-studio-gradle-and-ndk-integration/ (section Compiling your C/C++ source code from Android Studio) you can override this default behavior (ad-hoc makefile from gradle instructions).

    0 讨论(0)
提交回复
热议问题