Android prebuilt library! How solve?!

Android prebuilt library! How solve?!
0

#1

Hi guys, how i can link all static library at my android project (Android Studio)?! On xcode no problem, but android give me always problem with static library! I tried to check on all forum, but no solve.

Android.mk

LOCAL_PATH := $(call my-dir)
COCOS_ROOT := /Applications/cocos2d-x

include $(CLEAR_VARS)

$(call import-add-path,$(COCOS_ROOT))
$(call import-add-path,$(COCOS_ROOT)/external)
$(call import-add-path,$(COCOS_ROOT)/cocos)
$(call import-add-path,$(COCOS_ROOT)/cocos/audio/include)

LOCAL_MODULE := MyGame_shared

LOCAL_MODULE_FILENAME := libMyGame

LOCAL_SRC_FILES := $(LOCAL_PATH)/hellocpp/main.cpp \
                   $(LOCAL_PATH)/../../../Classes/AppDelegate.cpp \
                   $(LOCAL_PATH)/../../../Classes/HelloWorldScene.cpp

LOCAL_C_INCLUDES := $(LOCAL_PATH)/../../../Classes

# _COCOS_HEADER_ANDROID_BEGIN
# _COCOS_HEADER_ANDROID_END


LOCAL_STATIC_LIBRARIES := cocos2dx_static

# _COCOS_LIB_ANDROID_BEGIN
# _COCOS_LIB_ANDROID_END

include $(BUILD_SHARED_LIBRARY)

# $(call import-add-path, $(LOCAL_PATH)/../../../cocos2d)
$(call import-add-path, $(COCOS_ROOT))
$(call import-module, cocos)

# _COCOS_LIB_IMPORT_ANDROID_BEGIN
# _COCOS_LIB_IMPORT_ANDROID_END

settings.gradle

include ':libcocos2dx'

project(':libcocos2dx').projectDir = new File(settingsDir, '/Applications/cocos2d-x/cocos/platform/android/libcocos2dx')

include ':MyGame'

project(':MyGame').projectDir = new File(settingsDir, 'app')

#2

Try the additions I’ve listed in this:

LOCAL_PATH := $(call my-dir)
COCOS_ROOT := /Applications/cocos2d-x

include $(CLEAR_VARS)

$(call import-add-path,$(COCOS_ROOT))
$(call import-add-path,$(COCOS_ROOT)/external)
$(call import-add-path,$(COCOS_ROOT)/cocos)
$(call import-add-path,$(COCOS_ROOT)/cocos/audio/include)

LOCAL_MODULE := MyGame_shared

LOCAL_MODULE_FILENAME := libMyGame

LOCAL_SRC_FILES := $(LOCAL_PATH)/hellocpp/main.cpp \
                   $(LOCAL_PATH)/../../../Classes/AppDelegate.cpp \
                   $(LOCAL_PATH)/../../../Classes/HelloWorldScene.cpp

LOCAL_C_INCLUDES := $(LOCAL_PATH)/../../../Classes
# ADDED
LOCAL_C_INCLUDES += PATH_TO_YOUR_STATIC_LIB_HEADERS_ETC

# _COCOS_HEADER_ANDROID_BEGIN
# _COCOS_HEADER_ANDROID_END


LOCAL_STATIC_LIBRARIES := cocos2dx_static
# ADDED
LOCAL_STATIC_LIBRARIES += YourLibrary_static

# _COCOS_LIB_ANDROID_BEGIN
# _COCOS_LIB_ANDROID_END

include $(BUILD_SHARED_LIBRARY)

# $(call import-add-path, $(LOCAL_PATH)/../../../cocos2d)
$(call import-add-path, $(COCOS_ROOT))
$(call import-module, cocos)

# ADDED: I think this is only required if you need to build the library, where it has it's own Android.mk
$(call import-module, [PATH TO YOUR STATIC LIBRARY]) 

# _COCOS_LIB_IMPORT_ANDROID_BEGIN
# _COCOS_LIB_IMPORT_ANDROID_END

If you’re using Cocos2d-x 3.17+, then consider switching to the CMake way of doing things, which basically means you no longer use Android.mk etc, and CMakeLists.txt works for all platforms, so you don’t need to have different makefiles for different platforms.

http://docs.cocos2d-x.org/cocos2d-x/en/installation/CMake-Guide.html

Edit: Sorry had a mistake in the Android.mk listed above, so it’s now fixed.
Line:
LOCAL_STATIC_LIBRARIES := YourLibrary_static
Should be
LOCAL_STATIC_LIBRARIES += YourLibrary_static


#3

No have success with cmake.

External Native Build Issue:

...
...
-- MyGame prepare to use cpp needed libs: TREMOLO;PVMP3DEC;CPUFEATURES;ZLIB;MINIZIP;Tiny
XML2;FREETYPE;WEBSOCKETS;CURL;FLATBUFFERS;XXHASH;OPENSSL;JPEG;WEBP;TIFF;PNG;CHIPMUNK;BULLET;RECAST
-- Configuring incomplete, errors occurred!

#4

I like your changes. Hmmmm…


#5

What are the errors? You haven’t shown the actual errors, so there is no information to help diagnose the problem. Also, what are the contents of the main project gradle.build file, and the CMakeLists.txt file in the root folder of your game?


#6

CMakeLists.txt and cocos2d in root is present
I only make a new cocos project and i edited:

gradle.properties

PROP_APP_ABI=armeabi-v7a:x86
PROP_BUILD_TYPE=cmake

MyGame

    else if (PROP_BUILD_TYPE == 'cmake') {
        cmake {
            targets 'MyGame'
            arguments "-DCMAKE_FIND_ROOT_PATH=", "-DANDROID_STL=c++_static", "-DANDROID_TOOLCHAIN=clang", "-DANDROID_ARM_NEON=TRUE", \
                      "-DUSE_CHIPMUNK=TRUE", "-DUSE_BULLET=TRUE", "-DGEN_COCOS_PREBUILT=OFF", "-DUSE_COCOS_PREBUILT=ON"
            cppFlags "-frtti -fexceptions"

Log errors is about 500 rows, if need i post here.


#7

Have you already generated the pre-built libraries by first doing this:
"-DGEN_COCOS_PREBUILT=ON", "-DUSE_COCOS_PREBUILT=OFF"
then build it, then once the libraries are built, change it to this:
"-DGEN_COCOS_PREBUILT=OFF", "-DUSE_COCOS_PREBUILT=ON"

Also, have you defined a path for the pre-built libraries? Like this:
-DCOCOS_PREBUILT_ROOT=C:/Example/Libs"

Also, you don’t need to look at all 500 errors, just start at the top and figure out what is causing the issue. Can you at least paste the first 10 errors in the log, or upload it somewhere and provide a link to it?

I just tested it all by generating a new project, changing PROP_BUILD_TYPE=cmake in gradle.properties, building it, and it worked fine. The only thing I can think of that may be different is any fixes added to my copy of v3.17, one of which I can recall is for this issue:

and the diff is here if you want to merge it with your version:


#8

Have you already generated the pre-built libraries by first doing this:
"-DGEN_COCOS_PREBUILT=ON", "-DUSE_COCOS_PREBUILT=OFF"
then build it, then once the libraries are built, change it to this:
"-DGEN_COCOS_PREBUILT=OFF", "-DUSE_COCOS_PREBUILT=ON"

Yes i make it.
My path of prebuilt is: /Applications/cocos2d-x/prebuilt/mac/Debug
Here only mac directory after using cmake.

My errors is all same a this:

-- can't find cocos prebuilt library: cpufeatures
... and others..

#9

Riidio, did you even check the links I put in my previous post? It’s quite literally the fix for the issue of the missing cpufeatures library. Apply the fix, then rebuild, and see if that works for you.


#10

After cmake:

cmake ../test_app1 -DGEN_COCOS_PREBUILT=ON
make prebuilt

I have only library for mac in (Cocos_Root)/prebuilt/

I think problem is here, no android library…


#11

Riidio, the information you keep posting is vague, incomplete, and almost cryptic. I don’t know how to help you because of that, but maybe someone else here can actually decipher your posts.


#12

This post was flagged by the community and is temporarily hidden.


#13

What command is used to make android project with cmake? I have change this PROP_BUILD_TYPE=cmake and I am using cocos compile -p android but it looks like it is using build method ndk-build.


#14

I’m not sure if that command works for the cmake build. Open the proj.android up in Android Studio, and compile it in there. Someone else here may know if that command you’re using is supposed to work, or if there is an alternative set of commands to use.


#15

Thanks I will try with android studio now. One thing do we need some specific version of NDK ? or 14.1 will work?


#16

I am confused by following. Can you paste your actual value here and show me?

LOCAL_STATIC_LIBRARIES += YourLibrary_static

and here

BLOCAL_C_INCLUDES += PATH_TO_YOUR_STATIC_LIB_HEADERS_ETC

and

$(call import-module, [PATH TO YOUR STATIC LIBRARY]) .

My problem is that I am unable to link libcocos2dx correctly. I am not sure what I am doing wrong. Thanks.


#17

Well now I am stuck at this error.

Android NDK: Module MyGame_shared depends on undefined modules: cocos2dx_static
/Users/waqasahmad/Library/Android/sdk/ndk-bundle/build/core/build-binary.mk:706: *** Android NDK: Aborting (set APP_ALLOW_MISSING_DEPS=true to allow missing dependencies) . Stop.

This is my project mk file.

LOCAL_PATH := $(call my-dir)
COCOS_ROOT := /Users/waqasahmad/Documents/CocosBuilds/cocos2d-x

include $(CLEAR_VARS)

$(call import-add-path,$(COCOS_ROOT))
$(call import-add-path,$(COCOS_ROOT)/external)
$(call import-add-path,$(COCOS_ROOT)/cocos)
$(call import-add-path,$(COCOS_ROOT)/cocos/audio/include)

#$(call import-add-path,$(LOCAL_PATH)/…/…/…/cocos2d)
#$(call import-add-path,$(LOCAL_PATH)/…/…/…/cocos2d/external)
#$(call import-add-path,$(LOCAL_PATH)/…/…/…/cocos2d/cocos)
#$(call import-add-path,$(LOCAL_PATH)/…/…/…/cocos2d/cocos/audio/include)

LOCAL_MODULE := MyGame_shared

LOCAL_MODULE_FILENAME := libMyGame

LOCAL_SRC_FILES := $(LOCAL_PATH)/hellocpp/main.cpp
$(LOCAL_PATH)/…/…/…/Classes/AppDelegate.cpp
$(LOCAL_PATH)/…/…/…/Classes/HelloWorldScene.cpp

LOCAL_C_INCLUDES := $(LOCAL_PATH)/…/…/…/Classes

_COCOS_HEADER_ANDROID_BEGIN

_COCOS_HEADER_ANDROID_END

LOCAL_STATIC_LIBRARIES := cocos2dx_static

#LOCAL_STATIC_LIBRARIES += cocos2dx_static

_COCOS_LIB_ANDROID_BEGIN

_COCOS_LIB_ANDROID_END

include $(BUILD_SHARED_LIBRARY)

#$(call import-add-path, $(LOCAL_PATH)/…/…/…/cocos2d)
$(call import-add-path, $(COCOS_ROOT))
#$(call import-module, /Users/waqasahmad/Documents/CocosBuilds/cocos2d-x/cocos/platform/android/libcocos2dx)
$(call import-module, cocos)
#$(call import-module,(COCOS_ROOT)/cocos2d-x/cocos/Android.mk)

_COCOS_LIB_IMPORT_ANDROID_BEGIN

_COCOS_LIB_IMPORT_ANDROID_END

and my prebuilt folder is {COCOS_ROOT}/prebuilt.


#18

@tink3r_t I don’t understand what you’re doing. In one post you mention that you’re going to use cmake, and then in another you show your Android.mk file contents, which is not used as part of the cmake build.

So, let’s just go with getting the CMake build work, since it is the better way moving forward. This also assumes you’re using Cocos2d-x 3.17. Download android-ndk-r16b.

Make sure you have CMake installed. If not, go to cmake.org, and download the relevant cmake-3.12.4 for your operating system. After it is installed, open a console window and run the command “cmake --version” to make sure you see that it’s working.

Create a new Cocos2d-x 3.17 project with this command:

cocos new gamename -p com.example.game -l cpp -d .

Do NOT change anything in the /gamename/CMakeLists.txt file just yet. Leave it as it is for the time being just to make sure it compiles before you put anything extra in it.

Open gradle.properties which is in your proj.android folder.

Set this:
PROP_BUILD_TYPE=cmake

You may need to also set PROP_BUILD_TOOLS_VERSION=28.0.3 assuming you have that version of the build tools downloaded already.

In Android Studio (preferably version 3.2), open up the proj.android project. In the Android Studio menu, click File->Project Structure->SDK Location, and set the paths to the SDK and the NDK.

Now, build your project. That’s pretty much it. If you need add more source files after you’re sure that this builds and runs, then you can do so in the /gamename/CMakeLists.txt file.


#19

I want to use prebuilt libs with any method, (ndk-build or cmake) and no luck. While without prebuilt every thing works correctly. Problem is I don’t know how to link prebuilt libs for android.


#20

Go here:

http://docs.cocos2d-x.org/cocos2d-x/en/installation/CMake-Guide.html#prebuilt-libraries-feature

Read. It’s explained in there. Also, open up build.gradle which is in the /[gamename]/app/ folder, and find this section:

            else if (PROP_BUILD_TYPE == 'cmake') {
                cmake {
                    targets 'MyGame'
                    arguments "-DCMAKE_FIND_ROOT_PATH=", "-DANDROID_STL=c++_static", "-DANDROID_TOOLCHAIN=clang", "-DANDROID_ARM_NEON=TRUE", \
                              "-DUSE_CHIPMUNK=TRUE", "-DUSE_BULLET=TRUE"
                    cppFlags "-frtti -fexceptions"
                    // prebuilt root must be defined as a directory which you have right to access or create if you use prebuilt
                    // set "-DGEN_COCOS_PREBUILT=ON" and "-DUSE_COCOS_PREBUILT=OFF" to generate prebuilt,  this way build cocos2d-x libs
                    // set "-DGEN_COCOS_PREBUILT=OFF" and "-DUSE_COCOS_PREBUILT=ON" to use prebuilt, this way not build cocos2d-x libs
                    //arguments "-DCOCOS_PREBUILT_ROOT=/Users/laptop/cocos-prebuilt"
                    //arguments "-DGEN_COCOS_PREBUILT=OFF", "-DUSE_COCOS_PREBUILT=OFF"
                }
            }

The comments explain what to do.

First you set these:

arguments "-DCOCOS_PREBUILT_ROOT=/example/path/to/libs"
arguments "-DGEN_COCOS_PREBUILT=ON", "-DUSE_COCOS_PREBUILT=OFF"

For example, on Windows, you set the COCOS_PREBUILT_ROOT line this:

arguments "-DCOCOS_PREBUILT_ROOT=C:/Dev/Cocos2dLibs"

Now, build your project in Android Studio.

Then go back to the build.gradle file, and change this:

arguments "-DGEN_COCOS_PREBUILT=OFF", "-DUSE_COCOS_PREBUILT=ON"

Done. That line means you’re now going to use the pre-built libraries that you built with the previous command.

You are most likely to have an issue with cpufeatures lib missing, the fix for which is here: