I can make the prebuilt Cocos2D X C++ library using the following cocos command.
cocos gen-libs -p android
This command generates some *.a files in the <COCOS2DX_ROOT>/prebuilt/android folder. My question is how can I link these prebuilt libraries to the Android Studio project so that I don’t need to compile the Cocos2D X library every time I run cocos compile or cocos run.
Same here. I’m very interested too in using prebuilt libs with Android Studio.
So, I just created project:
cocos new TestLibs -p com.test.libs -l cpp -t binary
And there is no proj.android-studio but only proj.android folder. How properly import it into AS?
Try to summon @piotrros here - are you using AS with latest cocos2d-x and prebuilt libs?
I’m using ndkBuild. Yes - I can debug. Now (see topic above) I finally got it working with precompiled libs. Compilation is then much faster and I can still debug.
One import thing to get debugging working:
for releasing app you only need:
abiFilters “armeabi”
as adding more abis are increasing apk size and compilation time.
But, in my case, I own Nexus 6P with arm64-v8a so I have to add it to abiFilters in order to get debugging working.
I’m saying about c++ debugging, because java debugging will work anyway.
cocos new ProjectName -p projectname.com.name -l cpp -t binary
Configured it for build with prebuilt libs for iOS in Xcode. I even have it with source code, because I added path’s for cocos2d sources for header search path option.It compiles with prebuilt libs in no time and at the same time I have debug with source code of cocos2d. Cool.
Now, what should I do to set up it for Android Studio? There even no project folder created for it…
Now open proj.android-studio in Android Studio and enjoy.
If you want to debug c++ make sure you’ve added to abiFilters architecture, which your device is working on (for example arm64-v8a is needed for Nexus 6P). To find .cpp files expand ProjectName → cpp → Classes.
I’ve also attached example blank project, which I’ve created to write this post (and it’s working).
Thanks a lot for this. It just saved me a few hours. Also, I had to remove this because the cocos compile returned some weird error that the NDK is not set ¯_(ツ)_/¯. Thanks again!
Ok, it wasn’t working as expected. Whole cocos library was compiled instead. One small change is required:
$(call import-module,./prebuilt-mk)
instead of
$(call import-module,.)
in Android.mk file.
New test project included.
When you open this project in android studio you’ll see the difference. There’s no more bunch of libraries in ProjectName/cpp, just MyGame and cpufeatures (dunno why but it’s here).
I’m also switching from armeabi to armeabi-v7a, because non armeabi-v7a are very old and I don’t support them anyway (too old android version for libraries like google play services and facebook).
Now app is compiling for about 18 seconds (about 3mins before) in my case
Also I can debug on arm64-v8a devices with just armeabi-v7a (don’t have to add arm64-v8a in build.gradle which will increase apk size and compilation time). ProjectName.zip (5.8 MB)
For me NDK bundle and ANDROID_NDK_HOME are both set to “C:\dev\android-ndk-r13b-windows-x86_64\android-ndk-r13b” and compile works but on Nexux7 debug doesn’t.
Debugging depends on ABI your device have. For example in my Nexus 6P it’s arm64-v8, but it works also with armeabi-v7a. However I won’t be able to debug while using armeabi only. Nexus 7 should work with armeabi-v7a.