将本机模块从Gradle实验性插件迁移到稳定Gradle [英] Migrate Native Module from Gradle Experimental Plugin to Stable Gradle

查看:180
本文介绍了将本机模块从Gradle实验性插件迁移到稳定Gradle的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Android库项目,它通过 Android NDK
项目在一年前开始,因此我们选择使用实验插件,因为更好的NDK支持。
现在我正在使用 gradle-experimental:0.8.2 。我有一个 com.android.model.native 模块,我想将它迁移到 gradle:2.2.0 。我在 Gradle Android插件DSL 中看到的唯一选项是:

I have an Android Library project which has a part in C/C++ via Android NDK. The project started half of a year ago so we chose to use Experimental Plugin because of better NDK support. I'm using gradle-experimental:0.8.2right now. I have a com.android.model.native module and i would like to migrate it to gradle:2.2.0. The only option i see in Gradle Android Plugin DSL is:


  • AppExtension:用于 com.android.application 项目的android扩展。

  • LibraryExtension:用于 com.android.library 项目的android扩展。

  • TestExtension:用于<$ c $的android扩展c> com.android.test projects。

  • AppExtension: android extension for com.android.application projects.
  • LibraryExtension: android extension for com.android.library projects.
  • TestExtension: android extension for com.android.test projects.

所以问题是如何制作一个纯原生模块在gradle中使用稳定的gradle插件?

So the question is how to make a pure native module in gradle with stable gradle plugin?

这是我当前的本地模块:

Here is my current native module:

apply plugin: 'com.android.model.native'

apply from: "../config.gradle"
def config = ext.configuration

model {
    android {
        compileSdkVersion = config.compileSdkVersion
        buildToolsVersion = config.buildToolsVersion

        defaultConfig {
            minSdkVersion.apiLevel = config.minimumSdkVersion
            targetSdkVersion.apiLevel = config.targetSdkVersion
            versionCode = 1
            versionName = '1.0'
        }
        ndk {
            moduleName = 'apicore'
            platformVersion = config.minimumSdkVersion
            cppFlags.add("-std=c++11")
            cppFlags.add("-pthread")
            cppFlags.add("-fexceptions")
            cppFlags.add("-frtti")
            stl = "gnustl_static"
            abiFilters.addAll(config.targetPlatforms)
            ldLibs.addAll(['android', 'log'])
        }
        sources {
            main {
                jni {
                    source {
                        //include "someFile.txt"
                        // This is ignored.
                        exclude "main.cpp"
                        exclude "misc/APITest.cpp"
                        exclude "misc/APITest.h"
                    }
                }
            }
        }
        buildTypes {
            release {
                minifyEnabled false
                proguardFiles.add(file('proguard-android.txt'))
            }
        }
    }
}


推荐答案

我刚将项目从 Gradle实验性插件迁移到适用于Android的Gradle插件。目前针对Android的Gradle插件仍然没有提供从实验插件提供的com.android.model.native扩展,它是创建纯本地模块的能力。我必须认识到,我甚至不需要这个。我做了什么来取代com.android.model.native模块是我做了一个库模块,我处理本机代码和我的本地库的建设,我只是复制我需要它们的本地库。当然模块会生成.aar,但这不是问题,我只是不使用它。

I just migrated my project from Gradle Experimental Plugin to Gradle plugin for Android. The current Gradle plugin for Android still not provide something what com.android.model.native extension provided from the experimental plugin which is an ability to create a pure native module. I have to realise that i don't even need that. What i did to replace the com.android.model.native module is i made a library module where i handle the native code and building of my native libraries and i just copy the native libraries where i need them. Of course the module generate the .aar but thats not a problem i just don't use it.

这篇关于将本机模块从Gradle实验性插件迁移到稳定Gradle的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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