I've followed official guides to SDL on Android but its not making libmain.so

六月ゝ 毕业季﹏ 提交于 2019-12-11 23:13:08

问题


SDLActivity calls loadLibrary("main") but it's just libSDL2.so there. I struggled getting this far and have almost no experience of Android.mk, despite having built native android applications with cocos2d-x. Is it Android.mk I must investigate to create this library? I've got DinoMage's jni/src/main.c in place and have a stub extending SDLActivity under my package name.

Sorry for no code, there's lots, everywhere, only it's location and Android.mk could differ from DinoMage's guide, which approximates to the supplied readme for android anyway.

I'm using Eclipse for Windows 7x64

Here's the relevant logcat:

10-05 01:11:14.623: W/dalvikvm(3903): Exception Ljava/lang/UnsatisfiedLinkError; thrown while initializing Lorg/libsdl/app/SDLActivity;
10-05 01:11:14.623: W/dalvikvm(3903): Class init failed in newInstance call (Lmydomain/myproject/myactivity;)
10-05 01:11:56.760: D/AndroidRuntime(3903): Shutting down VM
10-05 01:11:56.761: W/dalvikvm(3903): threadid=1: thread exiting with uncaught exception (group=0x414bd908)
10-05 01:11:56.783: E/AndroidRuntime(3903): FATAL EXCEPTION: main
10-05 01:11:56.783: E/AndroidRuntime(3903): java.lang.ExceptionInInitializerError
10-05 01:11:56.783: E/AndroidRuntime(3903):     at java.lang.Class.newInstanceImpl(Native Method)
10-05 01:11:56.783: E/AndroidRuntime(3903):     at java.lang.Class.newInstance(Class.java:1319)
10-05 01:11:56.783: E/AndroidRuntime(3903):     at android.app.Instrumentation.newActivity(Instrumentation.java:1053)
10-05 01:11:56.783: E/AndroidRuntime(3903):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2104)
10-05 01:11:56.783: E/AndroidRuntime(3903):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2216)
10-05 01:11:56.783: E/AndroidRuntime(3903):     at android.app.ActivityThread.access$600(ActivityThread.java:149)
10-05 01:11:56.783: E/AndroidRuntime(3903):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1305)
10-05 01:11:56.783: E/AndroidRuntime(3903):     at android.os.Handler.dispatchMessage(Handler.java:99)
10-05 01:11:56.783: E/AndroidRuntime(3903):     at android.os.Looper.loop(Looper.java:153)
10-05 01:11:56.783: E/AndroidRuntime(3903):     at android.app.ActivityThread.main(ActivityThread.java:5022)
10-05 01:11:56.783: E/AndroidRuntime(3903):     at java.lang.reflect.Method.invokeNative(Native Method)
10-05 01:11:56.783: E/AndroidRuntime(3903):     at java.lang.reflect.Method.invoke(Method.java:511)
10-05 01:11:56.783: E/AndroidRuntime(3903):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1032)
10-05 01:11:56.783: E/AndroidRuntime(3903):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:790)
10-05 01:11:56.783: E/AndroidRuntime(3903):     at dalvik.system.NativeStart.main(Native Method)
10-05 01:11:56.783: E/AndroidRuntime(3903): Caused by: java.lang.UnsatisfiedLinkError: Couldn't load main: findLibrary returned null
10-05 01:11:56.783: E/AndroidRuntime(3903):     at java.lang.Runtime.loadLibrary(Runtime.java:365)
10-05 01:11:56.783: E/AndroidRuntime(3903):     at java.lang.System.loadLibrary(System.java:535)
10-05 01:11:56.783: E/AndroidRuntime(3903):     at org.libsdl.app.SDLActivity.<clinit>(SDLActivity.java:54)
10-05 01:11:56.783: E/AndroidRuntime(3903):     ... 15 more

I've tried this again using a different method of importing existing code (copied into workspace from extraction location) and set it up to get the same error, again. For a while I was missing libSDL2.so but I updated the manifest as the comments suggested and extended SDLActivity the missing libSDL2.so error was gone again. App went from 68k to 872k but this time the library is not visible within Eclipse. Now I still need libmain.so. and I haven't even bothered creating main.c this time, yet. Could this be the answer?

edit

Right track, I need main.c, or maybe not, but I got it anyway as the app doesn't appear to do anything otherwise.

Speaking of not doing anything Eclipse appears willing to run any old balls on my phone. I need to run ndk-build (as advised in the ndk documentation) and then I get, er, more errors, but at least they're compile time.

One important difference to DinoMage's advice comes with the wholesale copying over of the unzipped SDL to my new project. It will overwrite Android.mk. I've been playing around with different versions, the one which came with the project-android folder produces:

[armeabi] Compile thumb : main <= main.c
[armeabi] Compile thumb : main <= SDL_android_main.c
In file included from c:/Users/ME/workspace3/SDLActivity//jni/src/main/an droid/SDL_android_main.c:4:0:
c:/Users/ME/workspace3/SDLActivity//jni/src/main/android/../../SDL_intern al.h:34:24: fatal error: SDL_config.h: No such file or directory
compilation terminated.
make.exe: *** [c:/Users/ME/workspace3/SDLActivity//obj/local/armeabi/objs /main/main/android/SDL_android_main.o] Error 1

Which seems to explicitly differentiate it's main target from the other much longer Android.mk, from the root of the SDL directory. The longer one appears to target the other library I need SDL2, and fails to build that to, although for the very same reason

[armeabi] Compile thumb : SDL2 <= SDL.c
[armeabi] Compile thumb : SDL2 <= SDL_android_main.c
c:/Users/ME/workspace3/SDLActivity//jni/src/SDL_android_main.c:4:32: fata l error: ../../SDL_internal.h: No such file or directory
compilation terminated.
make.exe: *** [c:/Users/ME/workspace3/SDLActivity//obj/local/armeabi/objs /SDL2/src/SDL_android_main.o] Error 1

I've been through these includes and corrected a couple but I don't want to get into too deeply modifying the supposedly good library code.

Out of habit and to get things working better, I edited Android.mk in the subfolder jni/src to

LOCAL_SRC_FILES :=  main.c \
                    main/android/SDL_android_main.c

from the template

LOCAL_SRC_FILES := main.c \
                    $(SDL_PATH)/src/main/android/SDL_android_main.c

The whole jni/src/Android.mk is now:

LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := main
SDL_PATH := ../SDL

LOCAL_C_INCLUDES := $(LOCAL_PATH)/$(SDL_PATH)/include

# Add your application source files here...
LOCAL_SRC_FILES :=  main.c \
                    main/android/SDL_android_main.c

LOCAL_SHARED_LIBRARIES := SDL2
LOCAL_LDLIBS := -lGLESv1_CM -lGLESv2 -llog
include $(BUILD_SHARED_LIBRARY)

I think my paths are messed up but there are too many different ways to import this code into Eclipse and I've only found too ways that work even this much.


回答1:


A dirty hack would be changing

SDL_PATH := ../SDL

to

SDL_PATH := ../jni

since that is where we are told to paste it by, "Then copy (or symlink) the whole SDL directory and put it into your project’s jni directory"

This gets ndk-build chugging along for a while until failing to find EGL! which it never can, time for another question, or abandonment:

Android NDK: WARNING: Ignoring unknown import directory: "C:\Users\ME\workspace3\SDLActivity\jni\src"
[armeabi] Compile thumb  : SDL2 <= SDL.c
[armeabi] Compile thumb  : SDL2 <= SDL_android_main.c
[armeabi] Compile thumb  : SDL2 <= SDL_assert.c
[armeabi] Compile thumb  : SDL2 <= SDL_error.c
[armeabi] Compile thumb  : SDL2 <= SDL_hints.c
[armeabi] Compile thumb  : SDL2 <= SDL_log.c
[armeabi] Compile thumb  : SDL2 <= main.c
[armeabi] Compile thumb  : SDL2 <= SDL_audio.c
[armeabi] Compile thumb  : SDL2 <= SDL_audiocvt.c
[armeabi] Compile thumb  : SDL2 <= SDL_audiodev.c
[armeabi] Compile thumb  : SDL2 <= SDL_audiotypecvt.c
[armeabi] Compile thumb  : SDL2 <= SDL_mixer.c
[armeabi] Compile thumb  : SDL2 <= SDL_wave.c
[armeabi] Compile thumb  : SDL2 <= SDL_androidaudio.c
In file included from c:/Users/ME/workspace3/SDLActivity//jni/src/audio/a
ndroid/SDL_androidaudio.c:31:0:
c:/Users/ME/workspace3/SDLActivity//jni/src/audio/android/../../core/andr
oid/SDL_android.h:30:29: fatal error: EGL/eglplatform.h: No such file or directo
ry
compilation terminated.
make.exe: *** [c:/Users/ME/workspace3/SDLActivity//obj/local/armeabi/objs
/SDL2/src/audio/android/SDL_androidaudio.o] Error 1

The rest of the solution came from http://blog.csdn.net/jwzhangjie/article/details/9083827 ie creating Application.mk in jni directory to specify

APP_PLATFORM := android-9

This works but taking the advice of Ashoke would be optimal (re creating jni/SDL subfolder), if I'd just skipped to page 3 for DinoMage's tutorial where he states "Put the SDL_ttf source directory alongside your SDL directory in your project (in jni/ so you get jni/SDL_ttf" I'd know that.

[armeabi] Compile thumb : SDL2 <= SDL_test_md5.c
[armeabi] Compile thumb : SDL2 <= SDL_test_random.c
[armeabi] SharedLibrary : libSDL2.so
[armeabi] Install : libSDL2.so => libs/armeabi/libSDL2.so
[armeabi] Compile thumb : main <= SDL_android_main.c
[armeabi] Compile thumb : main <= main.c
[armeabi] SharedLibrary : libmain.so
[armeabi] Install : libmain.so => libs/armeabi/libmain.so

The demo from DinoMage now works.




回答2:


to create a shared library module named "main", in Android.mk you will need to declare

LOCAL_MODULE := main

this will result in "libmain.so" file.

please see this example



来源:https://stackoverflow.com/questions/26198562/ive-followed-official-guides-to-sdl-on-android-but-its-not-making-libmain-so

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!