cnlohr / rawdrawandroid

Build android apps without any java, entirely in C and Make
MIT License
3.55k stars 226 forks source link

Error while running my own C code. App closes. #10

Closed ghost closed 4 years ago

ghost commented 4 years ago

Hello, I downloaded the git and wanted to learn from scratch. While search online, i found the "hello-jni.c" Android NDK's example c program for JNI. I followed all the steps in the readme and i was able to load the the default test app and the app works. but when i try to do the same for the hello.c , the app closes.

and i get the following error when i do adb logcat | grep UnsatisfiedLinkError :

.... 12517:05-20 11:23:45.806 32051 32051 E AndroidRuntime: java.lang.UnsatisfiedLinkError: Unable to load native library "/data/app/org.yourorg.hello-edwqrnIee8oo7b-A2D2ggw==/lib/arm64/libhello.so": dlopen failed: cannot locate symbol "android_main" referenced by "/data/app/org.yourorg.hello-edwqrnIee8oo7b-A2D2ggw==/lib/arm64/libhello.so"... ......

the code : https://github.com/android/ndk-samples/blob/master/hello-jni/app/src/main/cpp/hello-jni.c

Thanks

cnlohr commented 4 years ago

@suresh321kumar Can you post a copy of your AndroidManifest.xml as well as the output from make?

ghost commented 4 years ago

AndroidManifest.xml file :

`<?xml version="1.0" encoding="utf-8" standalone="no"?>

<application android:debuggable="true" android:hasCode="false" android:label="@string/app_name" android:theme="@android:style/Theme.NoTitleBar.Fullscreen"  tools:replace="android:icon,android:theme,android:allowBackup,label" android:icon="@mipmap/icon"  android:requestLegacyExternalStorage="true">
    <activity android:configChanges="keyboardHidden|orientation" android:name="android.app.NativeActivity">
        <meta-data android:name="android.app.lib_name" android:value="@string/lib_name"/>
        <intent-filter>
            <action android:name="android.intent.action.MAIN"/>
            <category android:name="android.intent.category.LAUNCHER"/>
        </intent-filter>
    </activity>
</application>

`

output of make : _mkdir -p makecapk/lib/arm64-v8a /opt/android-sdk/ndk/21.1.6352462/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android29-clang -ffunction-sections -Os -fdata-sections -Wall -fvisibility=hidden -Os -DANDROID -DAPPNAME=\"hello\" -I./rawdraw -I/opt/android-sdk/ndk/21.1.6352462/sysroot/usr/include -I/opt/android-sdk/ndk/21.1.6352462/sysroot/usr/include/android -fPIC -I. -DANDROIDVERSION=29 -m64 -o makecapk/lib/arm64-v8a/libhello.so hello.c android_native_app_glue.c -L/opt/android-sdk/ndk/21.1.6352462/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/lib/aarch64-linux-android/29 -Wl,--gc-sections -s -lm -lGLESv3 -lEGL -landroid -llog -shared -uANativeActivity_onCreate mkdir -p makecapk/assets echo "Test asset file" > makecapk/assets/asset.txt rm -rf temp.apk /opt/android-sdk/build-tools/29.0.3/aapt package -f -F temp.apk -I /opt/android-sdk/platforms/android-29/android.jar -M AndroidManifest.xml -S Sources/res -A makecapk/assets -v --target-sdk-version 29 Found 1 custom asset file in makecapk/assets Configurations: (default)

Files: assets/asset.txt Src: () makecapk/assets/asset.txt mipmap/icon.png Src: () Sources/res/mipmap/icon.png values/strings.xml Src: () Sources/res/values/strings.xml AndroidManifest.xml Src: () AndroidManifest.xml

Resource Dirs: Type values values/strings.xml Src: () Sources/res/values/strings.xml Type mipmap mipmap/icon.png Src: () Sources/res/mipmap/icon.png Including resources from package: /opt/android-sdk/platforms/android-29/android.jar applyFileOverlay for drawable applyFileOverlay for layout applyFileOverlay for anim applyFileOverlay for animator applyFileOverlay for interpolator applyFileOverlay for transition applyFileOverlay for xml applyFileOverlay for raw applyFileOverlay for color applyFileOverlay for menu applyFileOverlay for font applyFileOverlay for mipmap Processing image: Sources/res/mipmap/icon.png (processed image Sources/res/mipmap/icon.png: 100% size of source) (new resource id icon from mipmap/icon.png #generated) Creating 'temp.apk' Writing all files... 'AndroidManifest.xml' (compressed 63%) 'assets/asset.txt' (not compressed) 'res/mipmap/icon.png' (not compressed) 'resources.arsc' (not compressed) Generated 4 files Included 0 files from jar/zip files. Checking for deleted files Done! unzip -o temp.apk -d makecapk Archive: temp.apk inflating: makecapk/AndroidManifest.xml
extracting: makecapk/assets/asset.txt
extracting: makecapk/res/mipmap/icon.png
extracting: makecapk/resources.arsc
rm -rf makecapk.apk cd makecapk && zip -D9r ../makecapk.apk . adding: resources.arsc (deflated 72%) adding: res/mipmap/icon.png (deflated 8%) adding: AndroidManifest.xml (deflated 63%) adding: assets/asset.txt (stored 0%) adding: lib/arm64-v8a/libhello.so (deflated 69%) jarsigner -sigalg SHA1withRSA -digestalg SHA1 -verbose -keystore my-release-key.keystore -storepass password makecapk.apk standkey adding: META-INF/MANIFEST.MF adding: META-INF/STANDKEY.SF adding: META-INF/STANDKEY.RSA signing: resources.arsc signing: res/mipmap/icon.png signing: AndroidManifest.xml signing: assets/asset.txt signing: lib/arm64-v8a/libhello.so

Signer X.509, CN=example.com, OU=ID, O=Example, L=Doe, ST=John, C=GB [trusted certificate]

jar signed.

Warning: The signer's certificate is self-signed. rm -rf aligned.apk /opt/android-sdk/build-tools/29.0.3/zipalign -v 4 makecapk.apk aligned.apk Verifying alignment of aligned.apk (4)... 50 META-INF/MANIFEST.MF (OK - compressed) 398 META-INF/STANDKEY.SF (OK - compressed) 816 META-INF/STANDKEY.RSA (OK - compressed) 1989 resources.arsc (OK - compressed) 2343 res/mipmap/icon.png (OK - compressed) 2505 AndroidManifest.xml (OK - compressed) 3448 assets/asset.txt (OK) 3543 lib/arm64-v8a/libhello.so (OK - compressed) Verification succesful ls -l aligned.apk -rw-r--r-- 1 suresh suresh 8535 May 20 12:07 aligned.apk echo "Installing" org.yourorg.hello Installing org.yourorg.hello adb install makecapk.apk Performing Streamed Install Success adb shell am start -n org.yourorg.hello/android.app.NativeActivity Starting: Intent { cmp=org.yourorg.hello/android.app.NativeActivity }_

ghost commented 4 years ago

i tried making changes to the sources/res/values/string.xml file too `<?xml version="1.0" encoding="utf-8"?>

hello hello org.yourorg.hello `
ghost commented 4 years ago

Im not sure what im doing wrong. steps i did :

  1. fresh git clone > created a new file hello.c and copy pasted the sample hello-jni.c sample code as above
  2. edited makefile => APPNAME?=hello and SRC?=hello.c
  3. edited AndroidManifes.xml => package="org.yourorg.hello"
  4. edited string.xml as above 5.make clean && make push run
  5. the app loads on the phone but closes.
cnlohr commented 4 years ago

Would you mind running:

objdump -T makecapk/lib/arm64-v8a/libhello.so 
cnlohr commented 4 years ago

If you are still having issues you may re-open this thread, but for now, I am closing it as I cannot repro this case where it can't find the main thing.