AndroidStudio 中的 NDK 支持以及在 Android Studio 和 Eclipse 之间进行选择 [英] NDK support in AndroidStudio and choosing between Android Studio and Eclipse

查看:25
本文介绍了AndroidStudio 中的 NDK 支持以及在 Android Studio 和 Eclipse 之间进行选择的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Android Studio 和 Eclipse 之间进行选择时遇到了竞争条件":

  1. 我的项目需要一些 C++ 代码才能与我的应用程序链接.目前,Android Studio 1.0 不支持 NDK(已弃用?!).说弃用并不能揭示整个丑陋的画面.目前还不清楚如何将预编译的 .so 库链接到项目.更不用说编译了...虽然很多解决方案每天都在stackoverflow中发布.大多数都与一些 pre-beta 版本有关,只是不工作,不是开箱即用,而且不是在浪费了大量时间检查它们之后.

到目前为止我检查过的解决方案:

<块引用>

一个.).基本前提是你用build中的指令替换Android.mkCore.mkCore2.mk.gradle 文件. 根据 http://ph0b.com/android-studio-gradle-and-ndk-integration/(从 Android Studio 编译你的 C/C++ 源代码部分)你可以覆盖这个默认行为(ad-来自 gradle 说明的 hoc 生成文件).

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 supported (deprecated ?!) in Android Studio 1.0. Saying deprecated does not reveal the whole UGLY PICTURE. Currently it's quite unknown how to even just link your pre-compiled .so libraries to a project. Not to talk about compiling... Although many many solutions to this are being posted in stackoverflow every day. Most of are related to some pre-beta versions, and just dont work, not out of the box, and not after wasting some considerable time cheking them.

Solutions I have checked so far:

a. NDK With Android Studio

b. Android studio, gradle and NDK

c. NDK gradle / Android Studio support, are you planning to release it?

d. Using the Android NDK with Android Studio- Part 1

e. Using the NDK with Android* Studio

f. Android Studio, gradle and NDK integration

All of which are quite different and complex to integrate, and just wont work...

  1. Developing for future Lollipop is, well, being blocked by Google, as they will just not allow using their new SDK's for some time now in Eclipse !?? Why?

Which brings me to the question. In which environemnt should I choose? Do google really care about their developers that much? Can't they just provide some simple usage solution for current version??

解决方案

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).

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).

这篇关于AndroidStudio 中的 NDK 支持以及在 Android Studio 和 Eclipse 之间进行选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆