使用android-ndk官方ndkbuild例子

Why this blog

现在(2018年9月27日),Android Studio中新建ndk项目都使用cmake而不是Android.mk+Application.mk的方式。但老项目需要维护,android.mk方式还需要过一遍。

本文在最新Android Studio中配置了https://github.com/googlesamples/android-ndk/tree/android-mk/hello-jni,并更新了gradle相应的配置。

整理后的代码地址在https://github.com/zchrissirhcz/toolbox/tree/master/android/hello-jni_ndkbuild

Get started

cd d:/work
git clone https://github.com/googlesamples/android-ndk
cd android-ndk
git checkout -b master-ndkbuild

拷贝hello-jni目录到d:/work/AndroidProjects/hello-jni_ndkbuild目录

用AS打开这个目录。发现是gradle构建的,但是新版AS有问题。

4.1 修改Project的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:2.3.0'
}
} allprojects {
repositories {
jcenter()
}
}

改成:

// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
google() //新增
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.3' //修改版本。注意,这个版本和gradle-wrapper.properties中的gradle版本不是一回事。
}
} allprojects {
repositories {
jcenter()
}
} // 新增
task clean(type: Delete) {
delete rootProject.buildDir
}

大坑

Project的build.gradle中的com.android.tools.build:gradle:3.1.3这个版本3.1.3,

gradle-wrapper.properties中的gradle版本不是一回事。

4.2 修改gradle-wrapper.properties中的gradle版本

原来:

distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip

新的:

distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip

4.3 去掉app的build.gradle中的buildToolsVersion

新版gradle中,这个buildToolsVersion有副作用。扔掉。

4.4 gradle sync;build

上一篇:[JS] 瀑布流加载


下一篇:Wide character in print at hcp.pl line 21.