PreBuilt Libraries, Android Studio & NDK_MODULE_PATH

PreBuilt Libraries, Android Studio & NDK_MODULE_PATH
0.0 0

#1

More idiotic questions and intractable problems.

I am using @piotrros example (http://discuss.cocos2d-x.org/t/how-to-link-prebuilt-cocos2d-x-c-library-to-android-studio-project/32949/11?u=piotrros) to demonstrate using prebuilts with Android Studio. My cocos compile for studio is failing and it is because my NDK_MODULE_PATH is NOT getting set.

Has anyone any ideas where my problem might be??

My errors look like:
Building native…
NDK build mode: debug
running: ‘/Users/NF/SDK/android-ndk-r13b/ndk-build -C /Users/NF/MobDev/Cocos/ProjectName/proj.android-studio/app -j2 NDK_MODULE_PATH=/Users/NF/MobDev/Cocos/ProjectName/proj.android-studio/…/cocos2d:/Users/NF/MobDev/Cocos/ProjectName/proj.android-studio/…/cocos2d/cocos:/Users/NF/MobDev/Cocos/ProjectName/proj.android-studio/…/cocos2d/external NDK_TOOLCHAIN_VERSION=4.9 NDK_DEBUG=1’

Android NDK: WARNING: Ignoring unknown import directory: /Users/NF/MobDev/Cocos/ProjectName/proj.android-studio/…/cocos2d
Android NDK: WARNING: Ignoring unknown import directory: /Users/NF/MobDev/Cocos/ProjectName/proj.android-studio/…/cocos2d/cocos
Android NDK: WARNING: Ignoring unknown import directory: /Users/NF/MobDev/Cocos/ProjectName/proj.android-studio/…/cocos2d/external
Android NDK: jni/Android.mk: Cannot find module with tag ‘./prebuilt-mk’ in import path
Android NDK: Are you sure your NDK_MODULE_PATH variable is properly defined ?

My jni/Android.mk:

LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := MyGame_shared
LOCAL_MODULE_FILENAME := libMyGame
LOCAL_SRC_FILES := hellocpp/main.cpp
…/…/…/Classes/AppDelegate.cpp
…/…/…/Classes/HelloWorldScene.cpp
LOCAL_C_INCLUDES := $(LOCAL_PATH)/…/…/…/Classes
# _COCOS_HEADER_ANDROID_BEGIN
# _COCOS_HEADER_ANDROID_END
LOCAL_STATIC_LIBRARIES := cocos2dx_static
# _COCOS_LIB_ANDROID_BEGIN
# _COCOS_LIB_ANDROID_END
include $(BUILD_SHARED_LIBRARY)
#$(call import-module,.)
$(call import-module,./prebuilt-mk)
# _COCOS_LIB_IMPORT_ANDROID_BEGIN
# _COCOS_LIB_IMPORT_ANDROID_END

My build.gradle:

apply plugin: ‘com.android.application’
android {
compileSdkVersion 23
buildToolsVersion “23.0.3”
defaultConfig {
applicationId “org.cocos2dx.ProjectName”
minSdkVersion 10
targetSdkVersion 23
versionCode 1
versionName “1.0”
ext {
cocospath=’/Users/NF/SDK/cocos2d-x-3.14.1’
}
externalNativeBuild {
ndkBuild {
targets “MyGame”
arguments “NDK_MODULE_PATH=$cocospath:$cocospath/cocos:$cocospath/external:$cocospath/cocos/prebuilt-mk:$cocospath/extensions”
arguments “-j” + Runtime.runtime.availableProcessors()
abiFilters “armeabi”
}
// available abiFilters (for debugging):
// abiFilters “x86”, “armeabi”, “armeabi-v7a”, “arm64-v8a”
}
}
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


#2

Why won’t you run project from Android Studio directly?

I just tried running from console and:

The android command is no longer available.

:smiley:

But it works from Android Studio.


#3

Hi @piotrros

It is failing to compile ‘cocos compile -p android -m debug --android-studio’ with this problem with NDK_MODULE_PATH. Any ideas? (Not tried to ‘cocos run…’ yet)

I have opened the main ProjectName folder in Android Studio (AS) and everything looks Ok, I can see the C++ files. I can ‘Build -> Make Module ‘ProjectName’’.

When I try to ‘Run -> Debug’ the system requests I ‘Edit Configuration…’. When I create a new (debug) configuration I select ‘Android App’ but then I am unable to select a ‘Module’…

  1. So I am unable to ‘cocos compile…’ because of some NDK_MODULEPATH problem…
  2. I seem unable to debug from AS because I do not know how to create a suitable module when I open your ‘ProjectName’ folder/project in AS…

Apologises for asking coming back with issue after issue. :confounded:


#4

You don’t have to create it by yourself. AS should automatically do this. Do you open proj.android-studio directly? It should like this:


#5

Thought I had this fixed. Unpacked your ProjectName project and updated settings for my environment. Imported to Android Studio and everything looked Ok.

Tried to debug on my device and got these errors. Looks like the build is trying to build my cocos2d-x source files in some strange ‘…/editor-support/…’ directory, see below. Any clues, thanks?


#6

Can you switch from Project to Android on the left?

Do you build precompiled libraries like this?:

cocos gen-libs -p android --app-abi armeabi-v7a

Also make sure android studio is using ndk r13b.


#7

Hi @piotrros, yes I can switch - see below. I built the precompiled libraries for all targets x86, armeabi & armeabi-v7a and, yes, currently using ndk r13b.

Still ‘seeing’ the C++ compile error. Think I shall give up on this until cocos2d-x 3.15.

Thanks for the support offered.


#8

Downloaded the second sample project above and set it up and this is the error message i get, any ideas?

Error while executing process C:\Users\Genesis\AppData\Local\Android\sdk\ndk-bundle\ndk-build.cmd with arguments {NDK_PROJECT_PATH=null APP_BUILD_SCRIPT=C:\Users\Genesis\Desktop\ProjectName\proj.android-studio\app\jni\Android.mk NDK_APPLICATION_MK=C:\Users\Genesis\Desktop\ProjectName\proj.android-studio\app\jni\Application.mk APP_ABI=armeabi-v7a NDK_ALL_ABIS=armeabi-v7a NDK_DEBUG=0 APP_PLATFORM=android-9 NDK_OUT=C:/Users/Genesis/Desktop/ProjectName/proj.android-studio/app/build/intermediates/ndkBuild/release/obj NDK_LIBS_OUT=C:\Users\Genesis\Desktop\ProjectName\proj.android-studio\app\build\intermediates\ndkBuild\release\lib NDK_MODULE_PATH=C:/Cocos/frameworks/cocos2d-x-3.10:C:/Cocos/frameworks/cocos2d-x-3.10/cocos:C:/Cocos/frameworks/cocos2d-x-3.10/external:C:/Cocos/frameworks/cocos2d-x-3.10/cocos/prebuilt-mk -j8 APP_SHORT_COMMANDS=false LOCAL_SHORT_COMMANDS=false -B -n}


#9

So you’re using Windows. In that case you cannot use “:” as path separator.
Instead use “;” like this:

arguments "NDK_MODULE_PATH=$cocospath;$cocospath/cocos;$cocospath/external;$cocospath/cocos/prebuilt-mk"

also make sure all paths are correct.


#10

Changed it and some of the errors went away and these stayed.

Error:(32) *** Android NDK: Aborting. . Stop.
Error:A problem occurred configuring project ‘:ProjectName’.

executing external native build for ndkBuild C:\Users\Genesis\Desktop\ProjectName\proj.android-studio\app\jni\Android.mk

also i do not have a prebuilt-mk at all, I have searched online and locally for it but do not have one.


#11

It seems like you’re using too old cocos version. You need at least 3.14.1. Also: did you generate prebuilt libs?


#12

downloaded 3.14,the reason i was using 3.10 is because i use cocos studio and i am already too far in to swap. I recall you saying in an another post that its possible to use 3.14 for cocos studio, can you tell me how?


#13

Well it just works for me. There are still classes to read Cocos Studio scenes in cocos2d-x 3.14 code.