I'm trying to cross-compile an Android executable (command line) that calls a method inside a proprietary android prebuilt shared object (.so aarch64)
I'm using an Ubuntu 20.04 x86_64 and I want cross-compile an executable for Android 10 aarch64.
The method is defined from the relative JNI in the following way:
public static native int getScore();
I build a simple C program:
#include <stdio.h>
extern int getScore();
int main(){
getScore();
return(1);
}
Then I develop an Android.mk file like the following:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := mygame
LOCAL_SRC_FILES := libmygame.so
include $(PREBUILT_SHARED_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := getscore
LOCAL_SRC_FILES := getscore.c
LOCAL_SHARED_LIBRARIES := mygame
include $(BUILD_EXECUTABLE)
Then I try to compile with:
ndk-build NDK_PROJECT_PATH=. APP_BUILD_SCRIPT=./Android.mk
But I get the follwoing error:
./obj/local/arm64-v8a/objs/getscore/getscore.o: In function `main':
/tmp/cross-compile-test/./getscore.c:24: undefined reference to `getScore'
clang++: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [/home/mark01/Android/Sdk/ndk/21.3.6528147/build/core/build-binary.mk:738: obj/local/arm64-v8a/getscore] Error 1
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…