我将gradle项目添加到Android Studio。 该项目的构建方式与之前类似:首先调用python脚本,该脚本将调用ndk-build来构建.so,然后调用gradle脚本来存档.apk。
导入到Android Studio后,我将一个externalNativeBuild块添加到build.gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion '25.0.0'
defaultConfig {
applicationId "org.cocos2dx.Game"
minSdkVersion 19
targetSdkVersion 23
versionCode 1
versionName "1.0"
externalNativeBuild {
ndkBuild {
abiFilters "x86"
arguments "-j3"
}
}
}
sourceSets.main {
java.srcDir "src"
res.srcDir "res"
jniLibs.srcDir "libs"
manifest.srcFile "AndroidManifest.xml"
assets.srcDir "assets"
}
signingConfigs {
release {
if (project.hasProperty("RELEASE_STORE_FILE")) {
storeFile file(RELEASE_STORE_FILE)
storePassword RELEASE_STORE_PASSWORD
keyAlias RELEASE_KEY_ALIAS
keyPassword RELEASE_KEY_PASSWORD
}
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
if (project.hasProperty("RELEASE_STORE_FILE")) {
signingConfig signingConfigs.release
}
}
debug {
debuggable true
jniDebuggable true
externalNativeBuild {
ndkBuild {
cFlags "-DDEBUG=1"
}
}
}
}
externalNativeBuild {
ndkBuild {
path "jni/Android.mk"
}
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile project(':libcocos2dx')
}
task cleanAssets(type: Delete) {
delete 'assets'
}
task copyAssets(type: Copy) {
from '../../Resources'
into 'assets'
}
clean.dependsOn cleanAssets
preBuild.dependsOn copyAssets
该项目已成功编译,安装并运行,但是在发生信号时,堆栈中的所有函数名称均为灰色,单击该函数无法导航到c ++代码(但函数名称正确)。如果手动打开代码,它将始终在代码顶部显示“此文件不属于项目”。
我很确定c ++代码已正确编译,这是怎么发生的?