here is my way for Windows users … it involves a bit of copying but it Works!!
the copying is just so we can use relative paths instead of absolute paths
this is exactly how i did setup my project along-with prebuilt libs and android studio and its all in details
am using ndk R13b and cocos2d-x 3.15
first i generate prebuilt libs using this command:
cocos gen-libs -p android --ap android-17 --app-abi armeabi-v7a
i used android-17 because thats what i had installed in the android sdk manager
then once finished create a new cocos2d-x project
then copy cocos2d-x-3.15(which contains prebuilt libs) inside the new project folder and remove the cocos2d folder inside it and then rename your newly copied cocos2d-x-3.15 folder to cocos2d
once again we’re doing all this copying so we don’t change a lot once we open up the project in android studio
then open up the project using android studio (wait a bit until the project is done setting up first) and go to
File->project structure
and set both sdk and ndk paths
then go to android.mk and replace:
$(call import-add-path,$(LOCAL_PATH)/../../../cocos2d/cocos/audio/include)
with this
$(call import-add-path,$(LOCAL_PATH)/../../../cocos2d/cocos/prebuilt-mk)
then in android studio go to build.gradel (Module: yourProjectName)
and copy this into it
import org.apache.tools.ant.taskdefs.condition.Os
apply plugin: 'com.android.application'
android {
compileSdkVersion 17 // use whatever platform you have
buildToolsVersion "26.0.1" //be careful in here to use a version of build Tools that you have
defaultConfig {
applicationId "org.cocos2dx.game"
minSdkVersion 10
targetSdkVersion 17
versionCode 1
versionName "1.0"
ext {
//read my explanation on how to change this path
cocospath = '/Users/Joseph/Documents/MyGameBin/cocos2d'
}
externalNativeBuild {
ndkBuild {
targets "MyGame"
arguments "NDK_MODULE_PATH=$cocospath;$cocospath/cocos;$cocospath/external;$cocospath/cocos/prebuilt-mk"
arguments "-j" + Runtime.runtime.availableProcessors()
abiFilters "armeabi-v7a"
}
}
}
sourceSets.main {
java.srcDir "src"
res.srcDir "res"
jniLibs.srcDir "libs"
manifest.srcFile "AndroidManifest.xml"
assets.srcDir "assets"
}
externalNativeBuild {
ndkBuild {
path "jni/Android.mk"
}
}
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
}
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile project(':libcocos2dx')
}
task cleanAssets(type: Delete) {
delete 'assets'
}
task copyAssets(type: Copy) {
from '../../Resources'
into 'assets'
}
clean.dependsOn cleanAssets
preBuild.dependsOn copyAssets
then go to yourProjectName then right click on cocos2d folder then properties then go to security tab then copy the full path
then now go back to build.gradel (Module: yourProjectName)
and paste the path in
cocospath ='your full path here'
now your path should look like this
cocospath = 'DriveName:\\Some\\Path\\yourProjectName\\cocos2d'
replace each double back slash with a single forward slash and also remove the drive name with the colons
here is how mine looks like
cocospath ='/Users/Joseph/Documents/MyGameBin/cocos2d'
then in android studio go to gradle.properties(Project Properties)
and change
PROP_APP_ABI=armeabi
to
PROP_APP_ABI=armeabi-v7a
then go to application.mk and change
APP_ABI := armeabi
to
APP_ABI := armeabi-v7a
now you are set so just run the project and your done!
PS: do exactly as i told and nothing else and it will Work!