Cocos2d-x v3.13 and sdk/ndk versions

SDK level is set by your self in command line. About NDK version, i think README has the information.

Yes, but now I do not know which version to use to be sure that there is no crash.

NDK r11+

I am not sure how to interpret it.
Is it all r11 versions (r11a, r11b, …) or all ndk versions from r11 and above (r12, r11)?

If anyone interested, it works fine on these devices when used v3.13 + sdk 19 + ndk r12b.

But I am still not sure if it works on all devices from 4.1.0 to 6.0.1.

Can someone else test it?

I will try later with same setup - but it really mess now - which NDK and Android SDK version to use for building project - would be good to have some kind table with cocos/NDK/Android SDK best version.

From my experience when Cocos2d-x stating that u should use NDK 11+ and then after using NDK 12 app starting randomly crash or not compiling it really confusing. In my understanding/expierence cocos engine newer works with latest NDK and Android SDK - so I’m confused which setup to choose…

Agree. For each cocos2dx version we should use fixed sdk/ndk version.
I think that it should be checked and forced in cocos console.
Right now everyone has different configuration and problems…

Regards
Chp

1 Like

It depends on which Android OS version do you want to run on. Android OS version and API level mapping can refer to this doc.

Default API level lies in APP_ROOT/proj.android/project.properties. But in pervious, cocos console will find the API level >= specified API level defined in project.properties. For example, the content of project.properties is

target=android-13

Cocos console will find 13 first, if not found then will found 14, and 15 until it found a API level that >= 13. We design like this is because developers may not have API 13, so it will be convenient to find a API that >= 13. And it works great until API 21, because API 21 break compatibility.

So changed the logic a few days ago in this patch, it will be included in v3.14. Cocos console will stop if it doesn’t find the specified API level.

I am not sure if i describe it clearly. And i am not sure if there is better way to fix it. Please let me know if you have any idea.

SDK 19 is Android 4.4, you can refer to this doc about API level and Android OS mapping. So it can not make sure that building with Android 4.4 dan run on Android 4.1.0. If you want to run on Android 4.1.0+, you should use API 16.

1 Like

Thank you! I am still a little confused, but I think that I will look deeper into the android documentation soon.

Hi,

Thank you for explanation. Does not mean that I can not create one app which will run on all Android 2.3.3+ devices?

I would like to have my app on as many as possible Android devices.
cocos2dx support Android 2.3.3+ (== SDK API 10)

Is there any point to use newer sdk api than 10 for cocos2dx game?
If no I think that we should use always SDK API 10 to be able to run on Android 2.3.3+

The same is about NDK. I think that we should always fix to one version.
Which ndk version do you use for developing/testing?
Which ndk version was used to build external libs (curl etc)?

I believe that we should always use one sdk/ndk configuration for cocos2dx release.

Which NDK version do you recommend for v3.13 (for v3.12 ndk12d does not work)?
android-ndk-r11c, android-ndk-r12b or some other?

Regards,
CHP

I think facebook and Google Play Services now requiring API 15+, there is now really no case to support 2.3.3+ - it’s ok to have 4.+. So I would recommend to use 19 or 22 API :slight_smile:

So 22 or 20?

If you are using Android Studio, do this:

In your gradle files, set the compile SDK version, the min SDK version, and target SDK version as you want. You can use ANY version that you want to use. I prefer to use the latest 23 or 24 for compile SDK and 22 for target SDK to not trigger Android 6 permissions, and I use min SDK as 14 as our app can’t run well on very old devices with very low power GPUs. But you can use any versions you want without worrying about any NDK related build issues or crashes.

Now comes the important part about NDK. Both cocos compile and NDK build ignore all these settings in your gradle file, instead they read the API version set in project.properties files. Set that as the minimum version you want to support, but at least version 13. This will not effect the Java build in Android Studio, this is only for NDK build.

Important: Check in your android studio sdk manager that Android SDK for BOTH your gradle compile sdk version and the project.properties sdk version is installed. Otherwise cocos compile command will try to use any version it can find, and also update your project.properties file. (As @zhangxm said, this behavior of cocos compile to search for any other available SDK will be changed in next release.).

If you are using Eclipse: I can’t help as I don’t know what effect changing project.properties will have on Java Android build with Eclipse.

This is only based on what I found out with my testing, please let me know if I am wrong or I missed something :slight_smile:

(This is with NDK r12b and Cocos2dx 3.13)

3 Likes

Thank you all for replies!

I looked in the documentation but I am still confused.

There are three entities

  • min sdk version - this api level is used at run time by android.

  • target sdk version - this api level is used at run time by android,
    android uses this setting to determine whether to enable any compatibility behaviors.

  • compile sdk version - this api level is used at compile time by cocos console,
    this api level is set by --ap android-xx.
    As I understand If I do not use super new api in the code or use runtime checks, then I expect backward compatibility with an earlier version of android.

I use a standard Hello World project. @zhangxm said that android ndk break compatibility since api 21, ok, so I use the sdk 19 and I do not understand why I should use the sdk 16 to be sure of the compatibility with 4.0.1.

Maybe the problem is that I did not have the min sdk version is installed
or is it a random ndk r12b error as @energyy said.

I will test it again this weekend.

I also think that now the actual min sdk version is 16.

@schngrg Do you test it on real 4.0.1 device or something like that?

Ok, now I installed the min sdk version. It is 16 in my case.

v3.13.1 + compile sdk 19 + ndk r12b

  • Ok on Galaxy S7 (6.0.1), Galaxy S6 (5.1.1), Galaxy Note 4 (4.4.4), Galaxy Tab 3 (4.1.1).

v3.13.1 + compile sdk 21 + ndk r12b

  • Ok on Galaxy S7 (6.0.1), Galaxy S6 (5.1.1), Galaxy Note 4 (4.4.4).
  • Crash on Galaxy Tab 3 (4.1.1).

v3.13.1 + compile sdk 24 + ndk r12b

  • Ok on Galaxy S7 (6.0.1), Galaxy S6 (5.1.1).
  • Crash on Galaxy Note 4 (4.4.4), Galaxy Tab 3 (4.1.1).

I used eclipse.

1 Like

The API level of 4.0.1 is 16. And i am not sure if you used API 17+ functions in Java codes, so i suggest you using API 16. There will have compiling error if you use API 17+ Java functions.

I found NDK break compatibility since 21, but i am not sure if 17 break any compatibility though i haven’t found anything.

Yea… Now I understand your idea. Thank you. :sunny:

So, to summarize, assuming a new game with cocos2D-X v3.13.1 (that may even use some SDKBOX plugins) our AndroidManifest.xml should have:

<uses-sdk android:minSdkVersion="16" android:targetSdkVersion="24" />

and, assuming we’re using ndk12b, we should compile it with:

cocos compile -p android --ap android-19

Am I correct? :smile:

You can use a different version if you want.
And if you can test it.

Theoretically, yes . But I tested with targetSdkVersion = 19.
I will test target 24 next week.

Yes, you are correct , you should compile with the app platform 19.

Sorry for the double post . I am writing on a tablet.

Hi

My game works on all devices I own despite the sdk version I use so can’t test here :frowning: But I’ve seen with google analytics that there are some devices whose execution time is 1 second, which resembles a crash to mee, that’s what I’m trying to minimize.

About targetSdkVersion, as API document posted before states that:

To maintain your application along with each Android release, you should increase the value of this attribute to match the latest API level, then thoroughly test your application on the corresponding platform version.

I check my game works with android 6.0 before release (moto g 2014 with stock rom). Been using targetSDKVersion=23 until recent update, and, as wrote before, I have had no problems I could detect until now (my game is really simple though).

Regards