本文主要介绍在android studio下实现jni单步调试时,所需要的配置及其步骤,这些也是本人经过几天折腾慢慢实现的,先提供给大家做参考:
1,配置是在mac下android studio实现的,主要是gradle版本以及build.gradle文件内容设置。
记住:NDK需要事先配置好,我是另外下载的NDK包(Ndk-r10e),配置教程请自己寻找,可以通过android studio的sdk管理工具中下载最新版。
1)主程序app下的build.gradle配置:
apply plugin: 'com.android.model.application'
model {
def signconf // <-- 重要
android {
compilesdkversion = 23
buildtoolsversion = "23.0.2"
defaultconfig.with {
applicationid = "这里写程序包名"
minsdkversion.apilevel = 10
targetsdkversion.apilevel = 23
versioncode = 5
versionname = "1.0"
}
}
android.signingconfigs { // <-- 重要
create("signrelease") { // <-- 重要
keyalias = '密匙文件名'
keypassword = '签名密码1'
storefile = file('签名文件名.key')
storepassword = '签名密码2'
storetype = "jks" // <-- 重要
signconf = it // <-- 重要
}
}
android.sources {
main {
jni {
source {
srcdir 'libs' //<--so文件目录
}
}
}
}
compileoptions.with {
sourcecompatibility = javaversion.version_1_7
targetcompatibility = javaversion.version_1_7
}
//配置so支持
android.ndk {
modulename = "allfree-jni"
ldlibs += "log"
abifilters += "armeabi"
abifilters += "armeabi-v7a"
abifilters += "x86"
abifilters += "arm64-v8a"
abifilters += "x86_64"
abifilters += "mips"
abifilters += "mips64"
}
android.buildtypes {
release {
minifyenabled = false
proguardfiles += file('proguard-rules.pro')
signingconfig = signconf
}
debug {
minifyenabled = false
proguardfiles += file('proguard-rules.pro')
signingconfig = signconf //--重要
}
}
}
repositories {
jcenter()
mavenCentral()
maven {
url "https://raw.githubusercontent.com/umeng/mvn-repo-umeng/master/repository" //这里引用友盟的sdk,可不加
}
maven {
url "http://repo1.maven.org/maven2/"
}
}
//依赖库
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.alibaba:fastjson:1.2.4'
compile 'com.android.support:support-v13:23.1.0'
compile 'com.android.support:recyclerview-v7:23.1.0'
compile project(':um_update')
compile 'com.loopj.android:android-async-http:1.4.9'
compile 'com.makeramen:roundedimageview:2.1.0'
compile project(':weiboSDK')
compile project(':android-ViewPagerIndicator')
}
2)gradle-wrapper.properties配置:
#Wed Dec 23 10:49:59 CST 2015
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.5-all.zip
3)全局build.gradle配置:
buildscript {
repositories {
jcenter()
}
dependencies {
//for jni
classpath 'com.android.tools.build:gradle:1.3.0'//可忽略
classpath 'com.android.tools.build:gradle-experimental:0.2.0'
}
}
allprojects {
repositories {
jcenter()
}
}
4)gradle.properties文件
# Project-wide Gradle settings.
# IDE (e.g. Android Studio) users:
# Gradle settings configured through the IDE *will override*
# any settings specified in this file.
# For more details on how to configure your build environment visit
# http://www.gradle.org/docs/current/userguide/build_environment.html
# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
# Default value: -Xmx10248m -XX:MaxPermSize=256m
# org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true
android.useDeprecatedNdk=true//必须
图1:
图2:
OK,配置完成,然后选择app-native后,debug-》app-native; 接下来就可以在C或C++文件中打断点开启Jni单步调试模式了,下面是我的项目截图:
图3:
图4:
其他可以参见Android NDK示例:https://github.com/googlesamples/android-ndk