PID: 15208 java.lang.UnsatisfiedLinkError: dalvik.system.PathClassLoader - android

I have just started learning cocos2d-x-3.11.1 in android studio (trying to compile with native C++ language) and I am getting this following error and a message on my phone "Unfortunately libcocos2dx has stopped"
java.lang.UnsatisfiedLinkError: dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/com.granjur.org-1/base.apk"],nativeLibraryDirectories=[/data/app/com.granjur.org-1/lib/arm64, /vendor/lib64, /system/lib64]]] couldn't find "libMyGame.so"
I have configured NDK, SDK and the ANT folders correctly from command line. I've been stuck with this from last two days!
AndroidManifest.xml
<uses-feature android:glEsVersion="0x00020000" />
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher">
<!-- Tell Cocos2dxActivity the name of our .so -->
<meta-data android:name="android.app.lib_name"
android:value="MyGame" />
<activity
android:name="org.cocos2dx.cpp.AppActivity"
android:screenOrientation="landscape"
android:configChanges="orientation|keyboardHidden|screenSize"
android:label="#string/app_name"
android:theme="#android:style/Theme.NoTitleBar.Fullscreen" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
<uses-permission android:name="android.permission.INTERNET"/>
</manifest>
logcat:
06-20 10:58:32.922 15649-15649/com.granjur.org E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.granjur.org, PID: 15649
java.lang.UnsatisfiedLinkError: dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/com.granjur.org-1/base.apk"],nativeLibraryDirectories=[/data/app/com.granjur.org-1/lib/arm64, /vendor/lib64, /system/lib64]]] 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:246)
at org.cocos2dx.lib.Cocos2dxActivity.onCreate(Cocos2dxActivity.java:260)
at android.app.Activity.performCreate(Activity.java:6251)
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:5422)
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)
06-20 10:59:39.226 15649-15649/com.granjur.org I/Process: Sending signal. PID: 15649 SIG: 9
Any help would be highly appreciated!
Thank you!

Run this command at the game directory to compile the source once:
cocos compile -p android --android-studio

Finally I have a genuine solution to the above problem for users working on android studio project of cocos2dx 3.8.1 above.
Just add this line in Application.mk :)
APP_ABI := armeabi-v7a
Sample Application.mk file :
APP_STL := gnustl_static
APP_CPPFLAGS := -frtti -DCC_ENABLE_CHIPMUNK_INTEGRATION=1 -std=c++11 -fsigned-char
APP_LDFLAGS := -latomic
ifeq ($(NDK_DEBUG),1)
APP_CPPFLAGS += -DCOCOS2D_DEBUG=1
APP_OPTIM := debug
APP_ABI := armeabi-v7a
else
APP_CPPFLAGS += -DNDEBUG
APP_OPTIM := release
APP_ABI := armeabi-v7a
endif
The main problem was the device architecture compatibility with your application. We need to give exclusive support to devices with ARM architecture armeabi-v7a when running proj.android-studio.
Hope this will help many other like me.

Related

java.lang.ClassNotFoundException: Didn't find class … on path: DexPathList

I'm trying to build SFML app for android, but getting some strange errors.
First, my app configured like that:
Android.mk
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := sfml-example
LOCAL_SRC_FILES := main.cpp
LOCAL_SHARED_LIBRARIES := sfml-system
LOCAL_SHARED_LIBRARIES += sfml-window
LOCAL_SHARED_LIBRARIES += sfml-graphics
LOCAL_SHARED_LIBRARIES += sfml-audio
LOCAL_SHARED_LIBRARIES += sfml-network
LOCAL_SHARED_LIBRARIES += sfml-activity
LOCAL_SHARED_LIBRARIES += openal
LOCAL_WHOLE_STATIC_LIBRARIES := sfml-main
include $(BUILD_SHARED_LIBRARY)
$(call import-module,third_party/sfml)
Application.mk
NDK_TOOLCHAIN_VERSION := 4.9
APP_PLATFORM := android-19
APP_STL := c++_static
APP_ABI := all
APP_MODULES := sfml-activity sfml-example
APP_OPTIM := release
APP_CFLAG := -g -O3
It's compiled and work fine on Android 5,6,7. But when I tried to launch app on android 6.0 I got an error:
java.lang.RuntimeException: Unable to start activity ComponentInfo{org.sfml_test.android/android.app.NativeActivity}: java.lang.IllegalArgumentException: Unable to load native library: /data/app/org.sfmldev.android-1/lib/arm/libsfml-activity.so
I found similar problem in this question.
So I tried to write activity, which should load SFML lib. Activity code:
package org.sfmldev.android;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
public class SFMLLoader extends Activity {
static {
System.loadLibrary("sfml-activity");
System.loadLibrary("sfml-example");
}
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Intent intent = new Intent(SFMLLoader.this, android.app.NativeActivity.class);
SFMLLoader.this.startActivity(intent);
}
}
And i change my AndroidManifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="org.sfmldev.android">
<uses-feature android:glEsVersion="0x00010001" />
<uses-permission android:name="android.permission.VIBRATE" />
<application android:label="#string/app_name"
android:icon="#drawable/sfml_logo"
android:hasCode="false"
android:allowBackup="false"
android:testOnly="false"
tools:ignore="GoogleAppIndexingWarning">
<activity android:name="org.sfmldev.android.SFMLLoader"
android:label="#string/app_name"
android:configChanges="keyboardHidden|orientation|screenSize">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="android.app.NativeActivity"
android:label="#string/app_name"
android:icon="#drawable/sfml_logo"
android:configChanges="keyboardHidden|orientation|screenSize">
<meta-data android:name="android.app.lib_name" android:value="sfml-activity" />
<meta-data android:name="sfml.app.lib_name" android:value="sfml-example" />
</activity>
</application>
</manifest>
And now I have new error on any devices:
java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{org.sfmldev.android/org.sfmldev.android.SFMLLoader}: java.lang.ClassNotFoundException: Didn't find class "org.sfmldev.android.SFMLLoader" on path: DexPathList[[directory "."],nativeLibraryDirectories=[/vendor/lib, /system/lib]]
I'm already tried to make relative path, disable instance run, clean project, restart android studio, restart OS, delete .idea and .gradle
You are supposed to load your library on runtime not on activity create:
public class SFMLLoader extends Activity {
static {
System.loadLibrary("sfml-activity");
System.loadLibrary("sfml-example");
}
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
...
}
}
Just forgot to remove android:hasCode="false" from AndroidManifest.xml

Exception Ljava/lang/UnsatisfiedLinkError; thrown while initializing in AOSP Build

Hi all I am using jni code to generate some number in my application. When I install and run it on my device it is working fine as expected with jni code, but when I am creating AOSP build flashing system.img and boot.img in my device getting UnsatisfiedLinkError at run time for jni code.
My Project structure, code snippet and logcat is given below
Below code is for JNI Wrapper class
RandomGenerator.java
public final class RandomGenerator {
private RandomGenerator() {}
public static native String getNumber(String code);
/***
* load native library in static initializer
*/
static
{
System.loadLibrary("code-generator");
}
}
Android.mk
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := code-generator
LOCAL_SRC_FILES := $(call all-cpp-files-under, samplecode/src/main/jni)
LOCAL_LDLIBS := -L$(SYSROOT)/usr/lib -llog
include $(BUILD_SHARED_LIBRARY)
Application.mk
APP_ABI := armeabi armeabi-v7a arm64-v8a
build.gradle
defaultConfig {
applicationId "com.jni.test.service"
minSdkVersion project.ext.minSdkVersion
targetSdkVersion project.ext.targetSdkVersion
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
signingConfig signingConfigs.config
multiDexEnabled true
ndk{
moduleName "code-generator"
}
}
sourceSets.main.jniLibs.srcDirs = ['./src/main/jni/']
externalNativeBuild {
// Encapsulates your CMake build configurations.
cmake {
// Provides a relative path to your CMake build script.
path "/src/main/jni/CMakeLists.txt"
}
}
And below on main application Android.mk code snippet.
Android.mk
#Building JNI library for Code generator
include $(CLEAR_VARS)
LOCAL_MODULE := code-generator
LOCAL_SRC_FILES := $(call all-cpp-files-under, samplecode/src/main/jni)
include $(BUILD_SHARED_LIBRARY)
#Build JNI library end
#Building sample application
include $(CLEAR_VARS)
LOCAL_MODULE_TAGS :=optional
LOCAL_SRC_FILES := $(call all-java-files-under, samplecode/src/main/java)
LOCAL_RESOURCE_DIR :=$(LOCAL_PATH)/samplecode/src/main/res
LOCAL_ASSET_DIR := $(LOCAL_PATH)/samplecode/src/main/assets
LOCAL_MANIFEST_FILE := samplecode/src/main/AndroidManifest.xml
LOCAL_PACKAGE_NAME := samplecode
LOCAL_SHARED_LIBRARIES := code-generator
LOCAL_SDK_VERSION := current
LOCAL_CERTIFICATE :=platform
LOCAL_PROGUARD_ENABLED := disabled
include $(BUILD_PACKAGE)
include $(CLEAR_VARS)
LOCAL_PREBUILT_STATIC_JAVA_LIBRARIES := j2xx:mylib/libs/j2xx.jar
include $(BUILD_MULTI_PREBUILT)
#Building sample application end
Now the problem is when I run android application with this code it is working fine as expected jni code, even AOSP build successfully completed. But When I flash AOSP build I getting
UnsatisfiedLinkError at runtime.
09-16 20:32:09.780 10782-10782/com.jni.test.service W/dalvikvm: Exception Ljava/lang/UnsatisfiedLinkError; thrown while initializing Lcom/jni/test/service/sample/RandomGenerator;
09-16 20:32:09.780 10782-10782/com.jni.test.service D/AndroidRuntime: Shutting down VM
09-16 20:32:09.780 10782-10782/com.jni.test.service W/dalvikvm: threadid=1: thread exiting with uncaught exception (group=0xb0cdcb20)
09-16 20:32:09.790 10782-11129/com.jni.test.service I/path: /data/data/com.jni.test.service/files/config.xml
09-16 20:32:09.800 10782-10782/com.jni.test.service E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.jni.test.service, PID: 10782
java.lang.UnsatisfiedLinkError:
Couldn't load code-generator from loader dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/com.jni.test.samplecode-2.apk"],nativeLibraryDirectories=[/data/app-lib/com.jni.test.samplecode-2, /vendor/lib, /system/lib]]]: findLibrary returned null
at java.lang.Runtime.loadLibrary(Runtime.java:358)
at java.lang.System.loadLibrary(System.java:526)
at com.jni.test.service.sample.RandomGenerator.<clinit>(Random.java:40)
at com.jni.test.service.MainActivity.onCreate(MainActivity.java:101)
at android.app.Activity.performCreate(Activity.java:5231)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
at android.app.ActivityThread.access$800(ActivityThread.java:135)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5017)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
at dalvik.system.NativeStart.main(Native Method)
Note: After AOSP build .so file creating related to code-generator but
not finding path in application, I believe something went wrong with
Android.mk configuartion. Please can someone help me on this.
Thanks in advance.

Error while running cocoa2dx project

Manifest
<application android:label="#string/app_name"
android:allowBackup="true" android:icon="#mipmap/ic_launcher">
<!-- Tell Cocos2dxActivity the name of our .so -->
<meta-data android:name="android.app.lib_name" android:value="MyGame" />
<activity ............../> </intent-filter> </activity>
</application>
Error:
com.xxx.xxxxxx E/AndroidRuntime: FATAL EXCEPTION: main Process: com.xxx.xxxxxxx, PID: 15913 java.lang.UnsatisfiedLinkError: dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/com.xxx.xxxxx-1/base.apk"],nativeLibraryDirectories=[/vendor/lib, /system/lib]]]
>couldn't find "libMyGame.so" at java.lang.Runtime.loadLibrary(Runtime.java:366)
at java.lang.System.loadLibrary(System.java:989)
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:5966)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2408)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2519)
at android.app.ActivityThread.access$800(ActivityThread.java:162)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1412)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:189)
at android.app.ActivityThread.main(ActivityThread.java:5532)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:950)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:745)
it redirect me in file
Cocos2dxActivity.java:248 in code line System.loadLibrary(libName);
I am stuck with this error. Help me.
I am using cocos2d-x-3.13
Android NDK, Revision 12
Latest SDK
Android-studio 2.1.3
python 2.7.12
apache-ant 1.9.7
JDK 1.8
Thanks in advance.
couldn't find "libMyGame.so"
This error happens because you didn't compiled for the architecture you are trying to test on.
Change to this in Application.mk file:
APP_ABI := armeabi armeabi-v7a x86
Then recompile and test.

How to solve the ClassNotFoundException of android project in eclipse?

I have a android project built with Eclipse. I can build the APK, but it crashed as the following logs:
E/AndroidRuntime(27898): java.lang.NoClassDefFoundError: Failed resolution of: Lcom/pili/pldroid/streaming/camera/demo/CameraStreamingActivity;
E/AndroidRuntime(27898): at com.example.rtmpdemo.MainActivity$1.onClick(MainActivity.java:35)
E/AndroidRuntime(27898): at android.view.View.performClick(View.java:4757)
E/AndroidRuntime(27898): at android.view.View$PerformClick.run(View.java:19757)
E/AndroidRuntime(27898): at android.os.Handler.handleCallback(Handler.java:739)
E/AndroidRuntime(27898): at android.os.Handler.dispatchMessage(Handler.java:95)
E/AndroidRuntime(27898): at android.os.Looper.loop(Looper.java:135)
E/AndroidRuntime(27898): at android.app.ActivityThread.main(ActivityThread.java:5258)
E/AndroidRuntime(27898): at java.lang.reflect.Method.invoke(Native Method)
E/AndroidRuntime(27898): at java.lang.reflect.Method.invoke(Method.java:372)
E/AndroidRuntime(27898): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:905)
E/AndroidRuntime(27898): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:700)
E/AndroidRuntime(27898): Caused by: java.lang.ClassNotFoundException: Didn't find class "com.pili.pldroid.streaming.camera.demo.CameraStreamingActivity" on path: DexPathList[[zip file "/data/app/com.example.rtmpdemo-1/base.apk"],nativeLibraryDirectories=[/data/app/com.example.rtmpdemo-1/lib/arm, /vendor/lib, /system/lib]]
E/AndroidRuntime(27898): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
E/AndroidRuntime(27898): at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
E/AndroidRuntime(27898): at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
E/AndroidRuntime(27898): ... 11 more
E/AndroidRuntime(27898): Suppressed: java.lang.NoClassDefFoundError: com.pili.pldroid.streaming.camera.demo.CameraStreamingActivity
E/AndroidRuntime(27898): at dalvik.system.DexFile.defineClassNative(Native Method)
E/AndroidRuntime(27898): at dalvik.system.DexFile.defineClass(DexFile.java:226)
E/AndroidRuntime(27898): at dalvik.system.DexFile.loadClassBinaryName(DexFile.java:219)
E/AndroidRuntime(27898): at dalvik.system.DexPathList.findClass(DexPathList.java:321)
E/AndroidRuntime(27898): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:54)
E/AndroidRuntime(27898): ... 13 more
E/AndroidRuntime(27898): Suppressed: java.lang.ClassNotFoundException: com.pili.pldroid.streaming.camera.demo.CameraStreamingActivity
E/AndroidRuntime(27898): at java.lang.Class.classForName(Native Method)
E/AndroidRuntime(27898): at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
E/AndroidRuntime(27898): at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
E/AndroidRuntime(27898): at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
E/AndroidRuntime(27898): ... 12 more
E/AndroidRuntime(27898): Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack available
W/ActivityManager( 810): Force finishing activity com.example.rtmpdemo/.MainActivity
I have defined the CameraStreamingActivity absolutely and registered in the AndroidManifest.xml. The structure of the project like this:
./AndroidManifest.xml
./assets
./libs
./libs/android-support-v4.jar
./libs/armeabi-v7a
./libs/armeabi-v7a/libpldroid_ffmpegbridge.so
./libs/pldroid-camera-streaming-1.2.0.jar
./lint.xml
./proguard-project.txt
./project.properties
./src
./src/com
./src/com/example
./src/com/example/rtmpdemo
./src/com/example/rtmpdemo/MainActivity.java
./src/com/pili
./src/com/pili/pldroid
./src/com/pili/pldroid/streaming
./src/com/pili/pldroid/streaming/camera
./src/com/pili/pldroid/streaming/camera/demo
./src/com/pili/pldroid/streaming/camera/demo/AudioStreamingActivity.java
./src/com/pili/pldroid/streaming/camera/demo/CameraStreamingActivity.java
./src/com/pili/pldroid/streaming/camera/demo/StreamingBaseActivity.java
./src/com/pili/pldroid/streaming/camera/demo/TestActivity.java
The AndroidManifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.rtmpdemo"
android:versionCode="1"
android:versionName="1.0" >
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-feature android:name="android.hardware.camera.autofocus" />
<uses-feature
android:glEsVersion="0x00020000"
android:required="true" />
<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="19" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.example.rtmpdemo.MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="com.pili.pldroid.streaming.camera.demo.CameraStreamingActivity" >
</activity>
<activity
android:name="com.pili.pldroid.streaming.camera.demo.AudioStreamingActivity"
android:label="#string/title_activity_audio_streaming" >
</activity>
<activity android:name="com.pili.pldroid.streaming.camera.demo.TestActivity" >
</activity>
</application>
</manifest>
HOWEVER, it works fine after i import the project into Android Studio.
The import-summary.txt as following:
ECLIPSE ANDROID PROJECT IMPORT SUMMARY
======================================
Ignored Files:
--------------
The following files were *not* copied into the new Gradle project; you
should evaluate whether these are still needed in your project and if
so manually move them:
* .DS_Store
* ic_launcher-web.png
* proguard-project.txt
Replaced Jars with Dependencies:
--------------------------------
The importer recognized the following .jar files as third party
libraries and replaced them with Gradle dependencies instead. This has
the advantage that more explicit version information is known, and the
libraries can be updated automatically. However, it is possible that
the .jar file in your project was of an older version than the
dependency we picked, which could render the project not compileable.
You can disable the jar replacement in the import wizard and try again:
android-support-v4.jar => com.android.support:support-v4:19.1.0
Moved Files:
------------
Android Gradle projects use a different directory structure than ADT
Eclipse projects. Here's how the projects were restructured:
* AndroidManifest.xml => app/src/main/AndroidManifest.xml
* assets/ => app/src/main/assets/
* libs/armeabi-v7a/libpldroid_ffmpegbridge.so => app/src/main/jniLibs/armeabi-v7a/libpldroid_ffmpegbridge.so
* libs/pldroid-camera-streaming-1.2.0.jar => app/libs/pldroid-camera-streaming-1.2.0.jar
* lint.xml => app/lint.xml
* res/ => app/src/main/res/
* src/ => app/src/main/java/
Next Steps:
-----------
You can now build the project. The Gradle project needs network
connectivity to download dependencies.
Bugs:
-----
If for some reason your project does not build, and you determine that
it is due to a bug or limitation of the Eclipse to Gradle importer,
please file a bug at http://b.android.com with category
Component-Tools.
(This import summary is for your information only, and can be deleted
after import once you are satisfied with the results.)
What did i miss?
Thanks.
Actually, your code don't have any problem. And this is the runtime error.
I sure that root cause is coming from libs which you import by wrong way.
"./libs/pldroid-camera-streaming-1.2.0.jar"
Try to remove this lib and import again by other way such as:
way 1: Java build path-> Libraries -> Add External JARS..
way 2: manual copy this lib directly to ".libs/" folder

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

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.
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.
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

Categories

Resources