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

本文是小编为大家收集整理的关于AndroidStudio中的NDK支持以及在Android Studio和Eclipse之间的选择的处理/解决方法,可以参考本文帮助大家快速定位并解决问题,中文翻译不准确的可切换到English标签页查看源文。

问题描述

我到了Android Studio和Eclipse之间的"竞赛条件":

  1. 我的项目需要一些C ++代码与我的应用程序链接.目前,在Android Studio 1.0中不支持(已弃用?!)不支持NDK.说弃用并没有揭示整个丑陋的照片.目前,甚至如何将您的预编译的.sto库链接到一个项目.不要谈论编译......虽然许多解决方案每天都在stackoverflow上发布.大多数与一些前β版本相关,只是不起作用,而不是开箱即用,而不是在浪费一些相当的时间cheking他们.

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

a. ndk与Android Studio

b. Android Studio,Gradle和Ndk

c. ndk gradle/android Studio支持,您是否计划释放它?

d. 使用Android Studio - 第1部分

e. 使用ndk与android * studio

f. Android Studio,Gradle和NDK Integration

所有这些都是完全不同和复杂的集成,只是不起作用...

  1. 开发未来的棒棒糖是,嗯,被谷歌阻止,因为他们现在不会允许使用新的SDK现在在Eclipse中使用新的SDK!??为什么?

让我想到这个问题. 我应该选择哪种环境? 谷歌真的关心他们的开发人员吗?不能为当前版本提供一些简单的使用解决方案??

推荐答案

目前,它非常赘述如何只需将您的预编译的.s子库库链接到项目.

不是真的.在过去,您将zip它们,将存档重命名为jar并将其包含在您的项目中.现在,您将ABI特定版本添加到<project>/<module>/src/main/jniLibs/<abi>目录(如果您没有更改Sourceets).

jnilibs目录结构

这有一个主要优势.您可以基于仅包括其特定本机库的ABI将结果.apk拆分为多个.以下代码示例将确保基于ABI获取多个.apk S,每个都将具有不同的versionCode,如下所示,如下所示:Axxxxxx其中A是ABI代码,您将获得原始版本的6位数字代码.样本代码应该在应用程序模块中使用.本机库将自动从所有应用程序的依赖项中挑选.

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
        }
    }
}

上面的例子在我的项目中很好地工作.

不要谈论编译...

考虑到我花了几个小时尝试将非本机库项目转换为一个并失败,我建议如果您已经开发了本机项目,请将其保留为并将其构建为.so s.

我会调查这个并在找到有用的东西后更新答案.然而,我已经发现了你的原始来源一个非常有趣( http://www.shaneenishry.com/blog/2014/08/17/ndk-with-android-studio/). 基本前提是您在build.gradle文件中替换Android.mk,Core.mk和Core2.mk.根据 http://ph0b.com/android-studio-gradle-andk-integration/(第Compiling your C/C++ source code from Android Studio)你可以覆盖此默认行为(从Gradle说明中覆盖ad-hoc makefile).

本文地址:https://www.itbaoku.cn/post/102764.html

问题描述

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

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