安卓工作室 1.3 NDK : cannot locate 'srand'

标签 android c android-ndk

如标题所述:运行我的 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'
}

这是我的 list :

<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 版本构建 native 源代码。 (Java 部分仍然可以使用最新的 SDK 构建。)

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

参见 https://stackoverflow.com/a/27338365/3115956https://stackoverflow.com/a/27093163/3115956有关此问题的更多解释。

关于安卓工作室 1.3 NDK : cannot locate 'srand' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31876608/

相关文章:

android - 方法 drawVertices() 没有在 Android Canvas 上绘制任何东西

c++ - GCC/g++ cout << 与 printf()

Android NDK r10: std::string 尚未声明

c - 无法插入链表

Android NDK 相机示例 JPEG(30 Hz)

android - undefined reference 错误使用静态库构建共享库

Android Studio 2.3 AVD 管理器变灰了吗?

android - 将 Nexus 7 锁定到只有一个 wifi 网络

android - 如何动态移动 ImageButton?

c - 预增量和后增量