I'm a first time user.
I have been attempting to build a plugin, following the excellent example on AppCodingEasy. This is what I did:
- export the project as AppCodingEasy suggests
- import the Eclipse project into Android Studio
- add an extra empty .cpp file to get round a bug in Android Studio/gradle The build fails if there is only one source file!
My build.gradle file now looks like this
apply plugin: 'com.android.application'
android {
compileSdkVersion 19
buildToolsVersion "20.0.0"
defaultConfig {
applicationId "com.foo.ExamplePlugin"
minSdkVersion 8
targetSdkVersion 19
ndk {
moduleName "lua"
stl "stlport_shared"
ldLibs "log"
abiFilters "armeabi", "armeabi-v7a"
}
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
dependencies {
compile files('libs/gideros.jar')
} |
And it nearly works ;-) The java builds OK and the cpp compiles OK. But I get a bunch of linker errors like this:
error: undefined reference to 'lua_tolstring'
error: undefined reference to 'lua_tolstring' |
Here is a full error line in case it illuminates something:
E:/lingos/androidNDK/toolchains/arm-linux-androideabi-4.6/prebuilt/windows/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld.exe: E:\design\android\ExamplePlugin\app\build\intermediates\ndk\debug\obj/local/armeabi/objs/lua/E_\design\android\ExamplePlugin\app\src\main\jni\ExamplePlugin.o: in function modifyString(lua_State*):ExamplePlugin.cpp(.text._ZL12modifyStringP9lua_State+0x134): error: undefined reference to 'lua_tolstring' |
One possiblity is that I don't have the build set up to generate the right target. I am supposed to be generating ????
Could a guru please confirm that lua references are being linked in from gideros.so?
Any ideas?
If you read this far, thanks for reading
Tim
Comments
The way I saw it before is creating jni folder with Android.mk file (just like in eclipse) and then gradle should automatically call ndk-build if it finds jni folder.
The directories under ...Plugin/app/src/main are aidl, assets, java, jni, jniLibs, and res. As I understand it (!) jniLibs is a relatively recent addition to the gradle world. jniLibs is the home for armeabi etc. and the shared libs.
Here is the Android.mk file. It sits in app/src/main:
Tim
http://stackoverflow.com/a/24083451/2274511
By default this will ignore your Android.mk and Application.mk files (thus not linking lua and other libs). As a workaround, you can tell gradle to disable atuomatic ndk-build call, then specify the directory for ndk sources manually.
It can be done by providing jniLibs.src
for example: to load precompiled liblua.so, libgideros.so, etc
You can also check other answers on that thread with some informative links
I also updated my NDK from v9 to v10, though that may not have been needed.
After the following changes to Android.mk, ndk-build now works splendidly:
1. change ../../libs to ../jniLibs
2. add lua at the end: LOCAL_SHARED_LIBRARIES := gideros lua
This builds and copies stuff from jniLibs to libs. And it ignores the empty file needed to get round a gradle bug. I then have to go into the libs directory and delete the duplicates or the Android packager complains about duplicate .so files in libs and jniLibs. There must be a way round that, but not that I could see.
Everything builds and packages OK! And loads to a device. As usual, the plugin builds as libmyPlugin.so. Case matters! That is a mini-bug in the original AppCodingEasy article.
BUT it doesn't run! Here is a bit of logcat:
Tim
Does it have a java file to which you reference through jni?
Did you modify activity to include both System.load and your java class in externalClasses?
So far I have only implemented a few simple functions, though separately I have developed code to use USB host mode. So now the challenge is to tie the two parts together, but that's just work ;-)
I plan to open source the Android Studio project in a few weeks time.
Tim