1

As the title states : When running my Android hybrid (Java/C) project, I get this error :

08-07 12:49:54.933    4546-4557/editor.lua.com.luaeditor E/AndroidRuntime﹕ FATAL EXCEPTION: GLThread 10
java.lang.ExceptionInInitializerError
        at editor.lua.com.luaeditor.Opengl_Renderer.onSurfaceChanged(Opengl_Renderer.java:28)
        at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1381)
        at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1138)
 Caused by: java.lang.UnsatisfiedLinkError: Cannot load library: reloc_library[1312]:  2123 cannot locate 'srand'...
        at java.lang.Runtime.loadLibrary(Runtime.java:434)
        at java.lang.System.loadLibrary(System.java:554)
        at editor.lua.com.luaeditor.Native.<clinit>(Native.java:12)
        at editor.lua.com.luaeditor.Opengl_Renderer.onSurfaceChanged(Opengl_Renderer.java:28)
        at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1381)
        at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1138)

To be safe, here are my build.grable :

apply plugin: 'com.android.application'

android {
    compileSdkVersion 21
    buildToolsVersion "22.0.1"
    defaultConfig {
        applicationId "editor.lua.com.luaeditor"
        minSdkVersion 10
        targetSdkVersion 10

        ndk {
            cFlags "-NDK_HOST_32BIT 1"
            cFlags "-std=c99"
            moduleName "Lua_Editor"
            ldLibs "GLESv2"
        }

        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    productFlavors {
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:22.2.1'
}

And here is my Manifest :

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="editor.lua.com.luaeditor">

<application android:allowBackup="true" android:label="@string/app_name"
    android:icon="@mipmap/ic_launcher" android:theme="@style/AppTheme">

    <uses-feature android:glEsVersion="0x00020000" android:required="true" />
    <activity
        android:name=".Lua_Editor"
        android:label="@string/app_name"
        android:screenOrientation="landscape"
        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>

By looking around the web and documentations, I found others have had the same issue : Android NDK: load_library: cannot locate srand The answer back then was to install the 32bit NDK.

With a little more digging around, i found that build-ndk had an option : NDK_HOST_32BIT 1

This option is supposed to force the NDK to compile to 32 bit.

Using Android Studio, so using gradle, i searched where i can add this option to configure the ndk, the only attempt that compiled was the attempt a pasted as my build.grable

Still, my error persists and I am keeping digging but the documentation on the android studio 1.3 preview ndk plugin seems low.

For information : I am running the app on an Samsung Galaxy S, compiling on a 64 bit Mint computer ( based on Ubuntu ).

So I am turning to you guys as a last resort. Am i stupid or am i stupid?

Community
  • 1
  • 1
Begah
  • 128
  • 9

1 Answers1

2

You need to build the native sources against a SDK version prior to 21, if you want the code to run on older versions. (The java part can still be built using the latest SDK.)

If it's ok to lower the generic compileSdkVersion, try lowering it to 19 or 20. If not, you might want to try adding compileSdkVersion 19 within the ndk block.

See https://stackoverflow.com/a/27338365/3115956 and https://stackoverflow.com/a/27093163/3115956 for more explanation on the issue.

Community
  • 1
  • 1
mstorsjo
  • 12,983
  • 2
  • 39
  • 62