Which API should I use?


#1

I compiled the my game application with API 26 (Android 8.0.0).

This app working on “Galaxy S7 edge (Android 7.0)” but it crashed on “Galaxy S4 (Android 5.0.1)”.

“Clash of Clans and etc. apps where on Google Play Store” works perfectly in these devices. Which API they are using?

How can I compile my game application like they?


#2

I’m using this app to check the targetAPI of the apps, but at Nov 2018 every app update (and new app) has to have at least targetAPI 26 -> see also Important TargetSDK and NDK changes in Android app publishing.

And you should understand the differences between targetSDK and minSDK. My minSDK is 19 (Android 4.4), so I’m sure the C++ code can’t use newer features. My targetSDK is 27 (Android 8.1), so I’m sure, the Java code is checked against it by lint while compile time.

Any other questions?


#3

1- Which API levels should be installed in my sdk folder?

2- Currently only API 26 is installed in my sdk folder.

3- Which API level should I write when compiling on Cmd?


#4

This is the targetSDK and 26 is fine.

I don’t know the used cmd of your build, because I just call in my proj.android folder the cmd ./gradlew build (on macOS).

And watching at the 3.17 sources (which is also in your proj.android folder) you can answer your question on your own.

It’s really hard for me to help you without any further information about your current setup. So I can only answer globally.

PS: Did you read and understand the links? Without minimal knowledge of Android builds, you can just copy’n’paste. This will lead to problems in the future, because as I mentioned above: at the end of 2018 you have to follow a new guideline for app updates.


#5

For example:

uses-sdk
android:targetSdkVersion="26"
android:minSdkVersion=“15”

If I do as above…
Do I need to have all APIs installed on my computer up from API 15 to API 26?

PS: “Did you read and understand the links?” (Yes I did read and understand the links.)


#6

No, you don’t need all of them. The target is enough.

Okay, what does the logcat tell you on the Galaxy S4. If you have minSdk = 15, so your Java/Kotlin code must not call any Android API-calls above 15 without an API-if-clause (e.g):

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { ... }

If the crash is within the C++ code, you have a bigger problem. :wink: Just kidding. Sometime Samsung phones does have shitty Android. I know for sure that e.g. Samsung has a really bad Bluetooth implementation.

PS: Did you test it within an emulator with Android 5? Is there the same error? - The emulator is often x86, so you need to add this to your ABI, because cocos default is only armeabi-v7a.


#7

uses-sdk
android:targetSdkVersion="26"
android:minSdkVersion=“15”

I do as above… But crash again on Galaxy S4.
Why? I tried for default cocos2dx app.


#8

What does the logcat say? I need any error message to go further…


#9

It say “Unfortunately, TestGame has stopped!”

If you want I can send you my .apk?


#10

Try also adding APP_PLATFORM := android-19 in your project\\proj.android\jni\Application.mk
Delete obj folder first and recompile, it should work.


#11

That’s not the logcat. That’s the alert dialog in the Android UI.

I need this, which is also visible in Android Studio.


#12

I am using Atom Editor.


#13

I will try.

So, Can I compile using API 19? Or I am is it just change the line in Android.mk?

Why should I delete the obj folder?


#14

So you have to use the adb command line tool to show you logcat within the terminal.


#15

If his minSdkVersion == 15, the android-19 for the ndk build can break devices with Android API 15 to 18. The minSdkVersion has always to be the same (or higher) as the APP_PLATFORM in the Application.mk file.


#16

No dont change anything, just add that line in Application.mk

If you make changes in any .mk files then you should delete obj folder, so it will compile again.

But this is what is working for me, many post in stackoverflow will tell you the same.
If minSdkversion is less than 19 than we have to add this in Application.mk file.
I tested this in many devices, it will work for sure and made many games with such config no problem so far.


#17

I wouldn’t bet on that. But if you see on the documentation you will see, that between 15 and 19 aren’t new header files, but the you can’t see the underlaying static libraries and this way it could break your game.

To be sure, that it’s working, I won’t differ both settings.

PS: I wouldn’t trust SO, because often the accepted answer isn’t the right one. It’s just a hint in my opinion, but you shouldn’t fully trust it.


#18

I got your point BUT if i dont add that line then its crashing for below 19 devices (100%).


#19

His test devices aren’t below API 19 :wink: But they crash… The main issue is, that we don’t know his error message from the logcat.


#20

Well Yeah, thats may be different issue.