Android Studio 1.3 NDK:找不到 'srand'

Android Studio 1.3 NDK : cannot locate 'srand'

如标​​题所述:当 运行 我的 Android 混合 (Java/C) 项目时,我收到此错误:

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)

为了安全起见,这是我的 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'
}

这是我的清单:

<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>

通过浏览网络和文档,我发现其他人也有同样的问题:Android NDK: load_library: cannot locate srand 当时的答案是安装32位的NDK。

经过进一步挖掘,我发现 build-ndk 有一个选项:NDK_HOST_32BIT 1

此选项应该强制 NDK 编译为 32 位。

使用 Android Studio,所以使用 gradle,我搜索了在哪里可以添加此选项来配置 ndk,唯一编译的尝试是粘贴为我的 build.grable

仍然,我的错误仍然存​​在,我一直在挖掘,但 android studio 1.3 预览版 ndk 插件的文档似乎很少。

有关信息:我是 运行 Samsung Galaxy S 上的应用程序,在 64 位 Mint 计算机上编译(基于 Ubuntu)。

所以我求助于你们作为最后的手段。是我傻还是我傻?

如果您希望代码在旧版本上 运行,则需要针对 21 之前的 SDK 版本构建本机源代码。 (java 部分仍然可以使用最新的 SDK 构建。)

如果可以降低通用 compileSdkVersion,请尝试将其降低到 19 或 20。如果不行,您可能想尝试在 ndk 块中添加 compileSdkVersion 19

有关此问题的更多说明,请参阅 and 。