[SOLVED] Can't run game on Android

Okay, there is another one feature that doesn’t work properly.
What’s wrong with that?

Since it’s internal code, I can’t affect it, I guess.

Windows, cocos 3.17

build settings

PROP_COMPILE_SDK_VERSION=27
PROP_MIN_SDK_VERSION=14
PROP_TARGET_SDK_VERSION=27
PROP_BUILD_TOOLS_VERSION=27.0.1
PROP_APP_ABI=armeabi-v7a:arm64-v8a:x86
PROP_BUILD_TYPE=ndk-build

I’m already using cocos for two weeks and 90% of time I’m trying to resolve problems, find documentation, understand why something doesn’t work at all instead of just creating a game.

Android is a tough beast to crack. I struggle with simple things getting stuff running where it just works on iOS and desktop platforms. I apologize for this.

Which NDK version are you using? What version of Android Studio? Are you trying to run on a hardware device or an emulator?

Thanks.

Android Studio 3.1.3
NDK 17.1.4828580
Emulator and Xiaomi Redmi 5 Note

I do not use AndroidStudio but cocosd-x.3.17 needs android-ndk-r16.

Below lines were copied from cocos2d-x CI script: \tools\appveyor-scripts\build.ps1, \tools\appveyor-scripts\before-build.ps1
That means that here https://ci.appveyor.com/project/minggo/cocos2d-x/history this build passed and it was running. I also use similar PowerShell script to build my apps without any problem.
.\tools\appveyor-scripts\setup_android.py - downloads proper android sdk and android-ndk-r16

mkdir C:/dev
cd c:/dev
git clone https://github.com/cocos2d/cocos2d-x.git
cd cocos2d-x

# checkout official release cocos2d-x-3.17
git checkout cocos2d-x-3.17

python download-deps.py --remove-download=False

git submodule init
git submodule update --recursive --depth=1
# download proper version of sdk and android-ndk-r16b
python -u .\tools\appveyor-scripts\setup_android.py

# set environment
$env:APPVEYOR_BUILD_FOLDER=$pwd.Path
$env:ANDROID_HOME=$env:APPVEYOR_BUILD_FOLDER + "\..\android-sdk"
$env:ANDROID_NDK_HOME=$env:APPVEYOR_BUILD_FOLDER + "\..\android-ndk-r16b"
$env:ANDROID_SDK_ROOT=$env:APPVEYOR_BUILD_FOLDER + "\..\android-sdk"
$env:NDK_ROOT=$env:APPVEYOR_BUILD_FOLDER + "\..\android-ndk-r16b"

# build 
cd $env:APPVEYOR_BUILD_FOLDER\tests\cpp-empty-test\proj.android\
./gradlew assembleRelease

I have no problems with building, I can’t run it.
Seems like only Creator can build an application, Android Studio can’t.
I have no idea how do you guys deal with it, to be honest.

I bet there is no way to build the same project for iOS?

Two run application you have to build application properly.

I gave you the steps that work for me and CI appveyor.

Those steps require git and Python 2.7, java (in my case jdk1.8.0_171). All other dependencies (including Android, NDK, SDK, build tools, compilers, gradle, …) are downloaded and set properly inside above script.

I guess that NDK 17.1.4828580 is your problem - try NDK 16
But maybe something else ( Android SDK, build tools, compilers, gradle, … )

Please try to build and run tests\cpp-empty-test\proj.android :slight_smile:

Well, thanks, I will surely try that, but…

The problem is in running cocos2d-x code. Debugger gives me exactly the line it breaks on.

I spend 99% of my development on desktop (windows or mac) - development/debugging on desktop is much faster than using emulator/device.
When everything works than:

./gradlew assembleRelease
adb install my.apk

No, I think it’s a wrong way.

How can I use engine when I’m not sure it works at all?
I can’t distribute my game with engine, I have to compile it.
But when engines isn’t able to do that, game is worthless.

Now I see that I can compile it only for Windows x64.
And I bet I have to thank Visual Studio for that.

UPD:
Tested with NDK 16 - the same issue, obviously.

Try to install and run on your device latest build from CI:
https://ci.appveyor.com/project/minggo/cocos2d-x/build/1.0.1154/job/ku2qr9q62hb1tkh5/artifacts

Agree
Script similar to that I gave is run after each commit to my repo.
After each commit I have latest version of my application on my Android device ready to testing.
But still I spend 99% of my development on desktop :slight_smile:

Me too, right after I got sure it works.

By the way, I solved my issue.

I had to add $(LOCAL_PATH)/hellocpp/main.cpp \ into LOCAL_SRC_FILES section.

Why it wasn’t there? Who called it “hellocpp”. Oh.

Thanks, anyway.