Android Native Activity 的 gradle 配置
最编程
2024-06-13 14:06:40
...
【深圳】源创会:5.26下午、轰趴馆等你”
实例项目的module结构
app module 的 manifests,其中android:value=”native-activity”与nativeactivity的build.gradle中的moduleName对应
<?xml version="1.0" encoding="utf-8"?><!-- BEGIN_INCLUDE(manifest) -->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.native_activity"
android:versionCode="1"
android:versionName="1.0">
<!-- This .apk has no Java code itself, so set hasCode to false. -->
<application
android:allowBackup="false"
android:fullBackupContent="false"
android:hasCode="false"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name">
<!-- Our activity is the built-in NativeActivity framework class.
This will take care of integrating with our NDK code. -->
<activity
android:name="android.app.NativeActivity"
android:configChanges="orientation|keyboardHidden"
android:label="@string/app_name">
<!-- Tell NativeActivity the name of or .so -->
<meta-data
android:name="android.app.lib_name"
android:value="native-activity" />
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest><!-- END_INCLUDE(manifest) -->
native module的manifests
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.foohao.nativeactivity">
<application/>
</manifest>
项目的build.gradle
// Top-level build file where you can add
// configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle-experimental:0.7.0'
}
}
allprojects {
repositories {
jcenter()
}
}
app module的 build.gradle
apply plugin: 'com.android.model.application'
model {
android {
compileSdkVersion = 23
buildToolsVersion = '23.0.3'
defaultConfig {
applicationId = 'com.example.native_activity'
minSdkVersion.apiLevel = 18
targetSdkVersion.apiLevel = 23
}
ndk {
platformVersion = 18
moduleName ='native-activity'
toolchain = 'gcc'
stl = 'gnustl_static'
cppFlags.add('-std=c++11')
ldLibs.addAll(['log', 'android', 'EGL', 'GLESv1_CM'])
}
sources {
main {
jni {
dependencies {
project ':nativeactivity' linkage 'static'
}
}
}
}
buildTypes {
release {
minifyEnabled = false
proguardFiles.add(file('proguard-rules.txt'))
}
}
}
}
nativeactivity module的 build.gradle
apply plugin: 'com.android.model.library'
def ndkDir = System.getenv("ANDROID_NDK_HOME")
def propertiesFile = project.rootProject.file('local.properties')
if (propertiesFile.exists()) {
Properties properties = new Properties()
properties.load(propertiesFile.newDataInputStream())
ndkDir = properties.getProperty('ndk.dir')
}
model {
android {
compileSdkVersion = 23
buildToolsVersion = "23.0.3"
defaultConfig.with {
minSdkVersion.apiLevel = 18
targetSdkVersion.apiLevel = 23
versionCode = 1
versionName = "0.0.1"
}
ndk {
moduleName = 'native-activity'
toolchain = 'gcc'
ldLibs.addAll(['log', 'android'])
ldFlags.add("-c")
}
sources {
main {
jni {
source {
srcDir "${ndkDir}/sources/android/native_app_glue"
}
exportedHeaders {
srcDir "${ndkDir}/sources/android/native_app_glue"
}
}
}
}
}
}
上一篇: 一文了解JVM(中)
推荐阅读
-
深度解析Android系统的定制配置
-
你不可不知的 React Native 混合用法(Android 篇)
-
揭秘Android APP native崩溃分析中时间的要诀
-
如何在Android Studio中使用Git小乌龟拉取项目? Git小乌龟的配置方法
-
在 Linux 平台上安装 Android 开发工具包 (SDK) 及 Native Development Kit(NDK) 的简易步骤
-
玩转Android技巧之一:深入理解Activity的启动模式
-
React Native Easy Toast: 一个轻量级且易上手的Android和iOS平台 toast 弹窗组件
-
在Java代码中设置Android设备的屏幕方向:screenOrientation属性的实用配置步骤
-
Android 项目编译 Gradle 配置说明
-
使用 Android 版 Gradle 构建时 Crunching Cruncher xxx.9.png 失败问题的解决方案