Help us with Android project setup

Help us with Android project setup
0.0 0

#25

it will, there is a database issue, currently. There is a topic about this issue.


#26

The database issue has been resolved.


#27

Here’s my (so far unsuccessful) experience using the latest installation instructions while trying to install the current tools for a new C++ cocos2d-x 3.16 project using Android Studio v3.0.1. I’m using the same Mac with High Sierra that was used for making my last game, which used Terminal commands to build for Android. But since Terminal commands no longer work for building cocos2d-x for Android, I’m now switching to Android Studio.

I stumbled across several different errors trying to build and run CppTests. The instructions don’t tell you that you need to import “build.gradle” to load a project into Android Studio, but I remembered this from my previous attempts at building cocos2d-x in Android Studio in the past. (Hint: instructions for running CppTests should mention build.gradle). Anyway, after trying lots of different things and searching online for clues as to the causes of my CppTests building problems, I ultimately decided that the PATH and environment variables that I set up for my previous Terminal-based project in .bash_profile were probably interfering with the operation of Android Studio. I therefore commented out every line of .bash_profile. Then I rebooted, completely uninstalled Android Studio using instructions at howchoo.com, and installed a fresh copy. I also got a fresh copy of cocos2d-x.

So now that I had a “clean” environment to work with I proceeded to build and run CppTests using the emulator for a Nexus 6P with API 25. But it is still failing with errors that give no clear indication stating how to fix them. A popup box says: “Application Installation Failed: … Failed to Finalize Session: INSTALL_FAILED_NO MATCHING_ABIS: Failed to extract native libraries, res = -113.” And in the Messages Gradle Build window is a red-error-circle on the line that says: “Android NDK: Application targets deprecated ABI(s): armeabi”. See this screenshot.

Why does this happen with a clean build, and what do I do to fix it? And how can you improve the installation instructions so that others don’t stumble here as well? If you want to attract new users to Cocos2d-x, it is important to give clear directions on how to get started, so that they don’t get discouraged and decide to try out other multi-platform environments like Unity.

Thanks for taking a look at this!


#28

The emulator ist not armeabi. So you need to add x86 to the target list or test on a real device.

See gradle.properties in proj.android-studio:

# List of CPU Archtexture to build that application with
# Available architextures (armeabi | armeabi-v7a | arm64-v8a | x86)
# To build for multiple architexture, use the `:` between them
# Example - PROP_APP_ABI=armeabi-v7a:arm64-v8a:x86
PROP_APP_ABI=armeabi

the last line has to be at least

PROP_APP_ABI=armeabi-v7a:x86

#29

The Instructions work for me, I tested them not long ago. Let me run through them again.


#30

Thanks for the tip, Mars3142! Now someone needs to update the the CppTests instructions to mention:

  • import the file named build.gradle
  • emulator uses x86, so update proj.android-studio/gradle.properties with the line: PROP_APP_ABI=armeabi-v7a:x86
    Then others won’t waste hours uninstalling, reinstalling, googling error messages, and generally trying to figure this out, like I have.

#31

Can you try building a cocos new .. and tell me if it works for you would of the box?


#32

This will give the same result because he uses an emulator.

and long ago


#33

Testing CppTests as well as the new project created by “cocos new …” both work, once you install all the sdk versions that are needed (by default, I believe gradle.properties requires version 14 and some others). I found myself being diverted to various references in order to: a) know that gradle.properties controls the required SDKs, b) figure out which of the four SDK version numbers in gradle.properties I should override, and why, and c) what PROP_APP_ABI does, and how I should change it so that it doesn’t use the deprecated “armeabi” value.

I have been unsuccessful at getting the emulator work reliably even after changing PROP_APP_ABI to x86 – It occasionally works, but never twice in a row, even with a reboot in between. Running on actual Android devices seems to be more straightforward, and maybe should be suggested for users who are just beginning to set this up.

I’d like to repeat that the command-line tool instructions say that you need to run setup.py before cocos new, but setup.py is very picky about the format of the input the user provides. As I mentioned above before I started using Android Studio, “I had several false starts because setup.py wasn’t documented well here. Is a trailing slash required on the ANDROID_NDK_PATH and ANDROID_SDK_ROOT? (yes it is.) Do you need to specify the bin sub-directory for your ANT_ROOT directory? (yes you do.)” I don’t know which of these environment variables are absolutely necessary if you only need to run “cocos new …”. And it was not easy finding the paths to these setup.py components so that they point to the ones that were previously installed by Android Studio. Some suggestions along these lines would be helpful.

I’m glad there is an interest in improving these installation instructions. I love open source projects, but I have observed with several open source projects that volunteer contributors are frequently more interested in adding new features, than they are keeping the documentation for beginners up to date.


#34

Thank you @doffen for your detailed replies. This process of building on Android has caused me many days of frustration. All of the documentation seems to be outdated and intermediates / beginners are left to piece together what they can.

I did get a Hello World to finally work on a device but after trying to integrate my iOS cocos2dx v3.16 code I could not rebuild. I tried starting again from scratch and could not get another Hello World to even build and run on Android.

It is unclear which combination of the many patch fixes I tried (downgrading my Java JDK, downgrading the NDK, updating gradle.properties, adjusting build.gradle, not downgrading gradle, etc.) need to be done to get it to work again. Multiple people have tried to talk me into just moving the game over to Unity. I am reaching out here in effort to stay with Cocos2dx.

Thank you to @slackmoehrle and the other authors for your invaluable time documenting and answering questions. It is unfortunate that as soon as you update something Google makes another meaningful change. If I find any clear, consistent solution I will reply an answer here.


#35

Hello Everyone! Back from Vacation! Anything I can help with that hasn’t already been done?

@slackmoehrle


#36

Ok, I got my new cocos2dx Hello World project running on a device again. I think the heart of the issue had to do with Armeabi being deprecated.

I tried @mars3142 solution but it was not enough (at least for me). The errors initially go away but on the attempt to run the build it just goes on forever and never builds. I had to Clean Project before they would reveal:

Error:(81) Android NDK: Application targets deprecated ABI(s): armeabi

There is also a lot of outdated or inaccurate Android Studio feedback on StackOverFlow to resolve this (including a suggestion to delete Application.mk and add a “task ndkClean(type: Delete) {...}” function to solve the error, which did not work for me either).

Here is what did work:

  • Open up Android.mk
  • Add this code above the “LOCAL_MODULE” line (though its specific location does not matter): APP_ABI := arm64-v8a armeabi-v7a x86 x86_64 and re-save.

I ran it again and it worked. As stated above it is unclear if another minor tangential change, update, or downgrade also contributed. I would lean on the experts for updating documentation or providing feedback for this otherwise. Hope this helps you!


#37

@zhangxm what do you currently need help with testing?


#38

@slackmoehrle i think you can test latest github codes to check:

  • all tests works
  • new projects works

since in the latest github codes, it uses clang+libc++, remove eclipse projects, remove armeabi, uses NDK r16+.


#39

@zhangxm sounds like fun! I’ll start this today and update this thread.

Community members, let 's help @zhangxm out with this testing too, please.


#41

@zhangxm a few things I am noticing

  1. cocos new output shows errors. bug?
$ cocos new MyAndroidTest -p com.com.com -l cpp -d .
Python 2.7.10
> Copy template into /Users/dubb/MyAndroidTest
> Copying Cocos2d-x files...
> Rename project name from 'HelloCpp' to 'MyAndroidTest'
> Replace the project name from 'HelloCpp' to 'MyAndroidTest'
/Users/dubb/MyAndroidTest/proj.android/.project is not found.
/Users/dubb/MyAndroidTest/proj.android/.cproject is not found.
/Users/dubb/MyAndroidTest/proj.android/AndroidManifest.xml is not found.
/Users/dubb/MyAndroidTest/proj.android/build.xml is not found.
/Users/dubb/MyAndroidTest/proj.android/res/values/strings.xml is not found.
/Users/dubb/MyAndroidTest/proj.android-studio/settings.gradle is not found.
/Users/dubb/MyAndroidTest/proj.android-studio/app/res/values/strings.xml is not found.
> Replace the project package name from 'org.cocos2dx.hellocpp' to 'com.com.com'
/Users/dubb/MyAndroidTest/proj.android/AndroidManifest.xml is not found.
/Users/dubb/MyAndroidTest/proj.android-studio/app/build.gradle is not found.
/Users/dubb/MyAndroidTest/proj.android-studio/app/AndroidManifest.xml is not found.
> Replace the Mac bundle id from 'org.cocos2dx.hellocpp' to 'com.com.com'
> Replace the iOS bundle id from 'org.cocos2dx.hellocpp' to 'com.com.com'
  1. Working with Android Studio after running Cocos new was delightful. I tried running my project and I didn’t have everything that was required installed. Android Studio walked me through what I was missing and my project built fine.

  2. running my project wasn’t so simple. It never runs for me on my Vivo X20:

01/11 17:49:57: Launching HelloCpp
$ adb install-multiple -r -t /Users/dubb/MyAndroidTest/proj.android/app/build/intermediates/split-apk/debug/dep/dependencies.apk /Users/dubb/MyAndroidTest/proj.android/app/build/intermediates/split-apk/debug/slices/slice_9.apk /Users/dubb/MyAndroidTest/proj.android/app/build/intermediates/split-apk/debug/slices/slice_8.apk /Users/dubb/MyAndroidTest/proj.android/app/build/intermediates/split-apk/debug/slices/slice_2.apk /Users/dubb/MyAndroidTest/proj.android/app/build/intermediates/split-apk/debug/slices/slice_6.apk /Users/dubb/MyAndroidTest/proj.android/app/build/intermediates/split-apk/debug/slices/slice_3.apk /Users/dubb/MyAndroidTest/proj.android/app/build/intermediates/split-apk/debug/slices/slice_4.apk /Users/dubb/MyAndroidTest/proj.android/app/build/intermediates/split-apk/debug/slices/slice_5.apk /Users/dubb/MyAndroidTest/proj.android/app/build/intermediates/split-apk/debug/slices/slice_1.apk /Users/dubb/MyAndroidTest/proj.android/app/build/intermediates/split-apk/debug/slices/slice_7.apk /Users/dubb/MyAndroidTest/proj.android/app/build/intermediates/split-apk/debug/slices/slice_0.apk /Users/dubb/MyAndroidTest/proj.android/app/build/outputs/apk/debug/HelloCpp-debug.apk 
Error while Installing APKs

But, on my Nexus 9 tablet it installs and runs fine.

Edit: I love the fact that Android Studio has a terminal window built in.


#42

@slackmoehrle

I fixed it in https://github.com/cocos2d/cocos2d-console/pull/436, and will update cocos2d-x’s sub module reference now.

I don’t know why your adb try to install so many APKs, what did you do?

 $ adb install-multiple -r -t /Users/dubb/MyAndroidTest/proj.android/app/build/intermediates/split-apk/debug/dep/dependencies.apk /Users/dubb/MyAndroidTest/proj.android/app/build/intermediates/split-apk/debug/slices/slice_9.apk /Users/dubb/MyAndroidTest/proj.android/app/build/intermediates/split-apk/debug/slices/slice_8.apk /Users/dubb/MyAndroidTest/proj.android/app/build/intermediates/split-apk/debug/slices/slice_2.apk /Users/dubb/MyAndroidTest/proj.android/app/build/intermediates/split-apk/debug/slices/slice_6.apk /Users/dubb/MyAndroidTest/proj.android/app/build/intermediates/split-apk/debug/slices/slice_3.apk /Users/dubb/MyAndroidTest/proj.android/app/build/intermediates/split-apk/debug/slices/slice_4.apk /Users/dubb/MyAndroidTest/proj.android/app/build/intermediates/split-apk/debug/slices/slice_5.apk /Users/dubb/MyAndroidTest/proj.android/app/build/intermediates/split-apk/debug/slices/slice_1.apk /Users/dubb/MyAndroidTest/proj.android/app/build/intermediates/split-apk/debug/slices/slice_7.apk /Users/dubb/MyAndroidTest/proj.android/app/build/intermediates/split-apk/debug/slices/slice_0.apk /Users/dubb/MyAndroidTest/proj.android/app/build/outputs/apk/debug/HelloCpp-debug.apk 

#43

This seems to be because of activated instant run. I would suggest to deactivate it, because I have more problems than help of that. And hot swap of code is mainly a feature for Java/Kotlin only projects, but we use native code and so we can’t have real benefits, I think.

@mozartalouis What’s your opinion on instant run? Use or don’t use?


#44

We probably shouldn’t use it. I wouldn’t work.

As you said, since were using native code, instant run give no benefits. The .so would be reloaded every time and in most cases, Android Studio will just run a full build anyways.


#45

@mars3142 @mozartalouis good to know, thanks. @slackmoehrle may be we should mention it in the docs?