FirebaseExtended / cocos2dx-cpp-sample

Firebase Cocos2d-x samples
http://firebase.google.com/games
MIT License
53 stars 25 forks source link

Compile error #10

Open minjisong7334 opened 7 years ago

minjisong7334 commented 7 years ago

Tried to build AdMob project in Android.

After typing this cmd "python setup_firebase_sample.py AdMob" I moved to sample_project folder and tried to build it but encoutnering this error. I'm using NDK version 15. Python 2.7.10 cocos2d-x-3.15 Cocos Console 2.3 Complie version 22

minjis-MacBook-Pro:sample_project minjisong$ pwd
/Users/minjisong/cocos2dx-cpp-sample/sample_project
minjis-MacBook-Pro:sample_project minjisong$ cocos compile -p android --ap android-22 --android-studio --app-abi armeabi-v7a
Python 2.7.10
Building mode: debug
Using Android Studio project : /Users/minjisong/cocos2dx-cpp-sample/sample_project/proj.android-studio
Building native...
NDK build mode: debug
running: '/Users/minjisong/Library/Android/sdk/ndk-bundle/ndk-build -C /Users/minjisong/cocos2dx-cpp-sample/sample_project/proj.android-studio/app -j4 APP_ABI="armeabi-v7a" NDK_MODULE_PATH=/Users/minjisong/cocos2dx-cpp-sample/sample_project/cocos2d:/Users/minjisong/cocos2dx-cpp-sample/sample_project/cocos2d/cocos:/Users/minjisong/cocos2dx-cpp-sample/sample_project/cocos2d/external NDK_TOOLCHAIN_VERSION=4.9 NDK_DEBUG=1'

Android NDK: Found platform level in ./project.properties. Setting APP_PLATFORM to android-22.    
Android NDK: WARNING: APP_PLATFORM android-22 is higher than android:minSdkVersion 1 in ./AndroidManifest.xml. NDK binaries will *not* be comptible with devices older than android-22. See https://android.googlesource.com/platform/ndk/+/master/docs/user/common_problems.md for more information.    
make: Entering directory `/Users/minjisong/cocos2dx-cpp-sample/sample_project/proj.android-studio/app'
[armeabi-v7a] Compile++ arm  : cocostudio_static <= WidgetReader.cpp
[armeabi-v7a] Compile++ arm  : cocostudio_static <= FlatBuffersSerialize.cpp
[armeabi-v7a] Compile++ arm  : cocostudio_static <= WidgetCallBackHandlerProtocol.cpp
[armeabi-v7a] Compile++ arm  : cocostudio_static <= CCComExtensionData.cpp
[armeabi-v7a] Compile++ arm  : cocostudio_static <= CocoStudio.cpp
[armeabi-v7a] Compile++ arm  : cocos_ui_static <= UILayoutComponent.cpp
[armeabi-v7a] Compile++ arm  : cocos_ui_static <= UITabControl.cpp
[armeabi-v7a] Compile++ thumb: audioengine_static <= CCThreadPool.cpp
[armeabi-v7a] Compile++ thumb: audioengine_static <= AssetFd.cpp
[armeabi-v7a] Compile++ thumb: audioengine_static <= AudioDecoder.cpp
[armeabi-v7a] Compile++ thumb: audioengine_static <= AudioPlayerProvider.cpp
[armeabi-v7a] Compile++ thumb: audioengine_static <= AudioResampler.cpp
/Users/minjisong/cocos2dx-cpp-sample/sample_project/cocos2d/cocos/audio/android/AudioDecoder.cpp: In constructor 'cocos2d::experimental::AudioDecoder::AudioDecoder(SLEngineItf, const string&, int, int, const FdGetterCallback&)':
/Users/minjisong/cocos2dx-cpp-sample/sample_project/cocos2d/cocos/audio/android/AudioDecoder.cpp:108:73: error: 'malloc' was not declared in this scope
     _pcmData = (char*) malloc(NB_BUFFERS_IN_QUEUE * BUFFER_SIZE_IN_BYTES);
                                                                         ^
/Users/minjisong/cocos2dx-cpp-sample/sample_project/cocos2d/cocos/audio/android/AudioDecoder.cpp: In destructor 'virtual cocos2d::experimental::AudioDecoder::~AudioDecoder()':
/Users/minjisong/cocos2dx-cpp-sample/sample_project/cocos2d/cocos/audio/android/AudioDecoder.cpp:126:18: error: 'free' was not declared in this scope
     free(_pcmData);
                  ^
/Users/minjisong/cocos2dx-cpp-sample/sample_project/cocos2d/cocos/audio/android/AudioDecoder.cpp: In member function 'bool cocos2d::experimental::AudioDecoder::decodeToPcm()':
/Users/minjisong/cocos2dx-cpp-sample/sample_project/cocos2d/cocos/audio/android/AudioDecoder.cpp:405:52: error: 'malloc' was not declared in this scope
         keyInfo = (SLMetadataInfo *) malloc(keySize);
                                                    ^
/Users/minjisong/cocos2dx-cpp-sample/sample_project/cocos2d/cocos/audio/android/AudioDecoder.cpp:434:25: error: 'free' was not declared in this scope
             free(keyInfo);
                         ^
/Users/minjisong/cocos2dx-cpp-sample/sample_project/cocos2d/cocos/audio/android/AudioDecoder.cpp: In member function 'bool cocos2d::experimental::AudioDecoder::resample()':
/Users/minjisong/cocos2dx-cpp-sample/sample_project/cocos2d/cocos/audio/android/AudioDecoder.cpp:504:42: error: 'malloc' was not declared in this scope
     void *outputVAddr = malloc(outputSize);
                                          ^
/Users/minjisong/cocos2dx-cpp-sample/sample_project/cocos2d/cocos/audio/android/AudioDecoder.cpp:594:17: error: 'free' was not declared in this scope
     free(convert);
                 ^
[armeabi-v7a] Compile++ thumb: audioengine_static <= AudioResamplerCubic.cpp
make: *** [obj/local/armeabi-v7a/objs-debug/audioengine_static/AudioDecoder.o] Error 1
make: *** Waiting for unfinished jobs....
make: Leaving directory `/Users/minjisong/cocos2dx-cpp-sample/sample_project/proj.android-studio/app'
Error running command, return code: 2.

Any solution for this?

alexames commented 7 years ago

I got some similar errors when building just now from a clean repo clone, but I was able to resolve it by making sure all my libraries were up to date. The easiest way to do this would be to open up the SDK manager (if you have Android Studio installed can go to Tools > Android > SDK Manager), and then click SDK Tools and update whatever updates you need to install, and try building again. If that doesn't resolve the issue for you let me know and I can dig around a little more.

minjisong7334 commented 7 years ago

I updated every tool thru SDK Manager but still compiling via cmd shows the same issue. Also, when I tried to run it in Android studio, the building process seems fine but it crashes in the app with this log.

08-04 10:13:00.155 3045-3045/? E/AndroidRuntime: FATAL EXCEPTION: main
                                                 Process: org.cocos2dx.hellocpp, PID: 3045
                                                 java.lang.UnsatisfiedLinkError: dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/org.cocos2dx.hellocpp-1/base.apk"],nativeLibraryDirectories=[/data/app/org.cocos2dx.hellocpp-1/lib/x86, /vendor/lib, /system/lib]]] couldn't find "libMyGame.so"
                                                     at java.lang.Runtime.loadLibrary(Runtime.java:367)
                                                     at java.lang.System.loadLibrary(System.java:1076)
                                                     at org.cocos2dx.lib.Cocos2dxActivity.onLoadNativeLibraries(Cocos2dxActivity.java:248)
                                                     at org.cocos2dx.lib.Cocos2dxActivity.onCreate(Cocos2dxActivity.java:264)
                                                     at android.app.Activity.performCreate(Activity.java:6237)
                                                     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107)
                                                     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369)
                                                     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
                                                     at android.app.ActivityThread.-wrap11(ActivityThread.java)
                                                     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
                                                     at android.os.Handler.dispatchMessage(Handler.java:102)
                                                     at android.os.Looper.loop(Looper.java:148)
                                                     at android.app.ActivityThread.main(ActivityThread.java:5417)
                                                     at java.lang.reflect.Method.invoke(Native Method)
                                                     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
                                                     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
alexames commented 7 years ago

You're probably getting that error because your C++ code isn't compiling.

Doing some quick searching, I found this person who had the same issue. Try following those directions and seeing that resolves the issue.

minjisong7334 commented 7 years ago

I checked that page too and did the way they said. Like the person replied, it doesn't work.

I guess it's a compatibility issue and I tried many other things but none of them work. So, I will just downgrade NDK, cocos2d, Android studio all things to make the environment that ppl posted worked well in their laptops.

Thanks for helping.

masimyildiz commented 6 years ago

malloc and free needs <stdio.h> header;

therefore please add #include <stdlib.h> to AudioDecoder.cpp and rebuild again.

I wish it works.

aslamca commented 6 years ago

libMyGame.so was not creating for me. I updated build.gradle this way

import org.apache.tools.ant.taskdefs.condition.Os //added

apply plugin: 'com.android.application'

android { compileSdkVersion 25 buildToolsVersion "26.0.1"

defaultConfig {
    applicationId "org.cocos2dx.hellocpp"
    minSdkVersion 14
    targetSdkVersion 25
    versionCode 1
    versionName "1.0"
    externalNativeBuild { //added this block
        ndkBuild {
            if (!project.hasProperty("PROP_NDK_MODE") || PROP_NDK_MODE.compareTo('none') != 0) {
                // skip the NDK Build step if PROP_NDK_MODE is none
                targets 'MyGame'
                arguments 'NDK_TOOLCHAIN_VERSION=4.9'
                arguments 'APP_PLATFORM=android-'+PROP_TARGET_SDK_VERSION

                def module_paths = [project.file("../../cocos2d").absolutePath,
                                    project.file("../../cocos2d/cocos").absolutePath,
                                    project.file("../../cocos2d/external").absolutePath]
                if (Os.isFamily(Os.FAMILY_WINDOWS)) {
                    // should use '/'
                    module_paths = module_paths.collect {it.replaceAll('\\\\', '/')}
                    arguments 'NDK_MODULE_PATH=' + module_paths.join(";")
                }
                else {
                    arguments 'NDK_MODULE_PATH=' + module_paths.join(':')
                }

                arguments '-j' + Runtime.runtime.availableProcessors()
                abiFilters.addAll(PROP_APP_ABI.split(':').collect{it as String})
            }
        }
    }
}

sourceSets.main {

    java.srcDir "src"
    res.srcDir "res"
    jniLibs.srcDir "libs"
    manifest.srcFile "AndroidManifest.xml"
    assets.srcDir "assets"
}
externalNativeBuild {//added this block
    ndkBuild {
        if (!project.hasProperty("PROP_NDK_MODE") || PROP_NDK_MODE.compareTo('none') != 0) {
            // skip the NDK Build step if PROP_NDK_MODE is none
            path "jni/Android.mk"
        }
    }
}
signingConfigs {

   release {
        if (project.hasProperty("RELEASE_STORE_FILE")) {
            storeFile file(RELEASE_STORE_FILE)
            storePassword RELEASE_STORE_PASSWORD
            keyAlias RELEASE_KEY_ALIAS
            keyPassword RELEASE_KEY_PASSWORD
        }
    }
}

buildTypes {

    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        if (project.hasProperty("RELEASE_STORE_FILE")) {
            signingConfig signingConfigs.release
        }
        externalNativeBuild {//added this block
            ndkBuild {
                arguments 'NDK_DEBUG=0'
            }
        }
    }
    debug {
        externalNativeBuild {//added this block
            ndkBuild {
                arguments 'NDK_DEBUG=1'
            }
        }
    }
}

}

dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) compile project(':libcocos2dx') compile 'com.google.firebase:firebase-auth:11.8.0' compile 'com.google.firebase:firebase-storage:11.8.0' compile 'com.google.android.gms:play-services-base:11.8.0' }

apply plugin: 'com.google.gms.google-services'

task cleanAssets(type: Delete) { delete 'assets' } task copyAssets(type: Copy) { from '../../Resources' into 'assets' }

clean.dependsOn cleanAssets preBuild.dependsOn copyAssets

//**** Also added following 2 lines on gradle.properties

PROP_TARGET_SDK_VERSION=13 PROP_APP_ABI=armeabi

Then I was able to create .so file but it was throwing no such method error from firebase. So I updated firebase and play service versions to 11.8.0 from 11.0.0 (above code already has 11.8.0).

Then again I started getting, "java.lang.UnsatisfiedLinkError: dlopen failed: cannot locate symbol "rand"... On lower versions(kitkat)

I used android-19 for compilation: cocos compile -p android --ap android-19 --android-studio --app-abi armeabi-v7a

Now the firebase app started working.