Wizcorp / Ejecta-X

A Fast, Open Source JavaScript, Canvas & Audio Implementation

Home Page:http://wizcorp.github.io/Ejecta-X

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Missing compiled libraries

hsalazarl opened this issue · comments

Hello,

I've been testing the libraries and I was able to add them to my project and compile them with the NDK.

As the NDK's documentation suggests, after running the "ndk-build" script it should:

The build tools copy the stripped, shared libraries needed by your application to the proper location in the application's project directory.

But, after I have executed the script, compiled my project, and ran my project on my device, I get the following error:

java.lang.UnsatisfiedLinkError: Couldn't load JavaScriptCore from loader dalvik.system.PathClassLoader[dexPath=/data/app/com.impactjs.ejecta.sample-2.apk,libraryPath=/data/app-lib/com.impactjs.ejecta.sample-2]: findLibrary returned null

I also built the android project that is at the branch, doing the same process with the NDK first, then execute the project and I get the same error.

I would appreciate any help towards this.

Best regards.

Hello,

In eclipse adt you need to add reference to Android sdk (14 or 13 i don t
remember sry)
Le 30 avr. 2014 04:15, "hsalazarl" notifications@github.com a écrit :

Hello,

I've been testing the libraries and I was able to add them to my project
and compile them with the NDK.

As the NDK's documentation suggests, after running the "ndk-build" script
it should:

The build tools copy the stripped, shared libraries needed by your
application to the proper location in the application's project directory.

But, after I have executed the script, compiled my project, and ran my
project on my device, I get the following error:

java.lang.UnsatisfiedLinkError: Couldn't load JavaScriptCore from loader dalvik.system.PathClassLoader[dexPath=/data/app/com.impactjs.ejecta.sample-2.apk,libraryPath=/data/app-lib/com.impactjs.ejecta.sample-2]: findLibrary returned null

I also built the android project that is at the branch, doing the same
process with the NDK first, then execute the project and I get the same
error.

I would appreciate any help towards this.

Best regards.


Reply to this email directly or view it on GitHubhttps://github.com//issues/65
.

I was on my mobile and my answer were very evasive...

click on the android button (here : http://www.tutomobile.fr/wp-content/uploads/2010/06/plugin_android_eclipse_6.png)

then search for android sdk 14, check the checkbox, install packages
it should be ok

hello @come,

Thanks for your response, I will take a look at it and will post the results in here.

Best regards.

Hello @come ,

Yeah, sorry, I forgot to mention my environment, I was trying to run my app with Android Studio, Gradle and Windows 8.1.

I solved the main problem I had, about native libraries not being found. I managed to fix the problem by adding the following to the sourceSet's main block in build.gradle file:

jniLibs.srcDir 'src/main/libs'
jni.srcDirs = []

The first one is to tell gradle the location of the native libraries to include them in the .apk, the second one is to disable the automatic execution of ndk-build script by gradle.
So you still can run the script manually from the console.

With those changes I was able to run my android project (with build tools and gradle versions updated), but there was still a problem with the shaders not being copied
to the "assets" folder, apparently the following lines of the Android.mk file are not being executed on my windows:

$(shell rm -r $(LOCAL_PATH)/../assets/www/shaders)
$(shell cp -r $(LOCAL_PATH)/../../../sources/ejecta/EJCanvas/2D/Shaders $(LOCAL_PATH)/../assets/www/shaders)

So I had to copy them by myself after the manual run of the ndk-build. And, as I wanted this entire process to be automatic, I kept investigating around gradle configuration and
created 2 tasks; one to compile the native libraries and the other to copy the shaders to the assets directory.

task ndkBuild(type: Exec) {

    Properties properties = new Properties()
    properties.load(project.rootProject.file('local.properties').newDataInputStream())
    def ndkDir = properties.getProperty('ndk.dir')

    if (Os.isFamily(Os.FAMILY_WINDOWS)) {
        commandLine ndkDir + '/ndk-build.cmd', '-C', file('src/main').absolutePath
    } else {
        commandLine ndkDir + '/ndk-build', '-C', file('src/main').absolutePath
    }
}

task copyShaders(type: Copy) {
    from 'sources/ejecta/EJCanvas/2D/Shaders'
    into 'src/main/assets/www/shaders'
}

The "ndkBuild" task needs the "ndk.dir" property to be set on the "local.properties" file, like so:

ndk.dir=C\:/android-ndk-r9d-windows-x86_64/android-ndk-r9d

This task executes the ndk-build script by changing the directory to "src/main" either for windows or linux/mac. And the copy shaders task just copy the "Shaders" directory to "assets/www/shaders".

I made these tasks to run prior the execution of the JavaCompile task, and the "copyShaders" task depend on the "ndkBuild" task, like this:

tasks.withType(Copy) { task ->
    task.dependsOn ndkBuild
}

tasks.withType(JavaCompile) { compileTask ->
    compileTask.dependsOn ndkBuild,copyShaders
}

And that's it. With that modifications to my build.gradle file I have automatic compilation of the native libraries and include them to the .apk file.

I hope this can help anyone else trying to run a project with Android Studio.

Best regards.

commented

Thanks @hsalazarl it's great to hear the project working on Windows and Android Studio. We don't support Android Studio right now, because it is still in Beta. I myself, am a big fan of AS, so it will be the choice IDE for this project once a major release is made :)

Going to close this for now.