- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在开发一个 Android 应用程序,其中使用 NDK 库,一切正常。在清理项目时,我收到此警告:
Android NDK: WARNING: APP_PLATFORM android-21 is larger than android:minSdkVersion 3 in ./AndroidManifest.xml
当我转到 Activity 查看 native 代码的结果时,出现以下异常:
05-10 13:01:33.001: E/AndroidRuntime(15024): java.lang.UnsatisfiedLinkError: Native method not found: com.zitza.murncy.activities.HelloJni.stringFromJNI:()Ljava/lang/String;
05-10 13:01:33.001: E/AndroidRuntime(15024): at com.zitza.murncy.activities.HelloJni.stringFromJNI(Native Method)
05-10 13:01:33.001: E/AndroidRuntime(15024): at com.zitza.murncy.activities.HelloJni.onCreate(HelloJni.java:36)
下面给出了我的 Activity 类以及头文件和 list 。
我的HelloJni类(class)
package zitza.murncy.activities;
import android.app.Activity;
import android.widget.TextView;
import android.os.Bundle;
public class HelloJni extends Activity
{
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
/* Create a TextView and set its content.
* the text is retrieved by calling a native
* function.
*/
TextView tv = new TextView(this);
tv.setText( stringFromJNI() );
setContentView(tv);
}
/* A native method that is implemented by the
* 'hello-jni' native library, which is packaged
* with this application.
*/
public native String stringFromJNI();
/* This is another native method declaration that is *not*
* implemented by 'hello-jni'. This is simply to show that
* you can declare as many native methods in your Java code
* as you want, their implementation is searched in the
* currently loaded native libraries only the first time
* you call them.
*
* Trying to call this function will result in a
* java.lang.UnsatisfiedLinkError exception !
*/
public native String unimplementedStringFromJNI();
/* this is used to load the 'hello-jni' library on application
* startup. The library has already been unpacked into
* /data/data/com.example.hellojni/lib/libhello-jni.so at
* installation time by the package manager.
*/
static {
System.loadLibrary("hello-jni");
}
}
我的Android.mk文件
# Copyright (C) 2009 The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := hello-jni
LOCAL_SRC_FILES := hello-jni.c
include $(BUILD_SHARED_LIBRARY)
我的Application.mk文件
APP_ABI := all
我的hello-jni.c
#include <string.h>
#include <jni.h>
/* This is a trivial JNI example where we use a native method
* to return a new VM String. See the corresponding Java source
* file located at:
*
* apps/samples/hello-jni/project/src/com/example/hellojni/HelloJni.java
*/
jstring
Java_com_example_hellojni_HelloJni_stringFromJNI( JNIEnv* env,
jobject thiz )
{
#if defined(__arm__)
#if defined(__ARM_ARCH_7A__)
#if defined(__ARM_NEON__)
#if defined(__ARM_PCS_VFP)
#define ABI "armeabi-v7a/NEON (hard-float)"
#else
#define ABI "armeabi-v7a/NEON"
#endif
#else
#if defined(__ARM_PCS_VFP)
#define ABI "armeabi-v7a (hard-float)"
#else
#define ABI "armeabi-v7a"
#endif
#endif
#else
#define ABI "armeabi"
#endif
#elif defined(__i386__)
#define ABI "x86"
#elif defined(__x86_64__)
#define ABI "x86_64"
#elif defined(__mips64) /* mips64el-* toolchain defines __mips__ too */
#define ABI "mips64"
#elif defined(__mips__)
#define ABI "mips"
#elif defined(__aarch64__)
#define ABI "arm64-v8a"
#else
#define ABI "unknown"
#endif
return (*env)->NewStringUTF(env, "AIzaSUhfkedpl0AS8" ABI ".");
}
我的 list 文件
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.murncy"
android:versionCode="3"
android:versionName="3.0" >
<!-- <uses-sdk android:minSdkVersion="3" /> -->
<uses-sdk
android:minSdkVersion="10"
android:targetSdkVersion="18" />
<uses-permission android:name="android.permission.CALL_PHONE" />
<uses-permission android:name="android.permission.SEND_SMS" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.GET_TASKS" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permission.WRITE_CONTACTS" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<!-- If c2dm permission is removed, parse starts working, else c2dm takes control -->
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<permission
android:name="com.murgency.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
<uses-permission android:name="com.murncy.permission.C2D_MESSAGE" />
<application
android:name="com.zitza.murncy.MUrgencyApplication"
android:allowBackup="true"
android:icon="@drawable/icon"
android:label="@string/app_name"
android:theme="@style/Sherlock.__Theme.Light" >
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="AIzaSyAiJ3CMj_kKyjgWa-tNSLjUhfkedpl0AS8" />
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
<activity
android:name="com.zitza.murncy.activities.HelloJni"
android:label="Testing Native Code"
android:screenOrientation="portrait" />
<activity
android:name="com.zitza.murncy.activities.SplashScreen"
android:screenOrientation="portrait"
android:theme="@style/AppTheme"
android:windowSoftInputMode="stateAlwaysHidden" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<!-- Contact change listener on boot -->
<service android:name="com.zitza.services.ContactService" />
<receiver
android:name="com.zitza.services.BootReceiver"
android:enabled="true"
android:exported="false" >
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
<service android:name="com.zitza.services.ContactService" />
<service
android:name="com.zitza.services.GPSLoggerService"
android:enabled="true"
android:exported="true"
android:permission="android.permission.ACCESS_FINE_LOCATION" >
</service>
<!-- Parse push -->
<service android:name="com.parse.PushService" />
<!-- <receiver -->
<!-- android:name="com.parse.GcmBroadcastReceiver" -->
<!-- android:permission="com.google.android.c2dm.permission.SEND" > -->
<!-- <intent-filter> -->
<!-- <action android:name="com.google.android.c2dm.intent.RECEIVE" /> -->
<!-- <action android:name="com.google.android.c2dm.intent.REGISTRATION" /> -->
<!-- <category android:name="com.murgency" /> -->
<!-- </intent-filter> -->
<!-- </receiver> -->
<receiver android:name="com.parse.ParseBroadcastReceiver" >
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.USER_PRESENT" />
</intent-filter>
</receiver>
<!-- Custom receiver -->
<!-- <receiver -->
<!-- android:name="com.zitza.services.ParsePushReceiver" -->
<!-- android:exported="false" > -->
<!-- <intent-filter> -->
<!-- <action android:name="android.intent.action.BOOT_COMPLETED" /> -->
<!-- <action android:name="android.intent.action.USER_PRESENT" /> -->
<!-- <action android:name="com.murgency.UPDATE_STATUS" /> -->
<!-- </intent-filter> -->
<!-- </receiver> -->
<!-- GCM -->
<service
android:name="com.zitza.services.GcmIntentService"
android:enabled="true" />
<receiver
android:name="com.zitza.services.GcmBroadcastReceiver"
android:permission="com.google.android.c2dm.permission.RECEIVE" >
<intent-filter android:priority="1" >
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<action android:name="com.murncy.UPDATE_STATUS" />
<category android:name="com.murncy" />
</intent-filter>
</receiver>
</application>
</manifest>
最佳答案
要获得 native 函数的正确签名,您可以自动创建 JNI header :
/* JNI header: this header can be build automatically with "javah":
* javah -classpath bin/classes -d jni activities.murncy.zitza.HelloJni
* (maybe you have to add "-bootclasspath /opt/android-sdk/platforms/android-21/android.jar")
*/
#include "activities_murncy_zitza_HelloJni.h"
要避免出现警告,您可以将以下内容添加到 Application.mk
:
# minimium Android version
APP_PLATFORM := android-10
编辑
javah -bootclasspath /opt/android-sdk/platforms/android-10/android.jar -classpath bin/classes -d jni activities.murncy.zitza.HelloJni
(当然你必须调整Android SDK的安装路径)
关于java.lang.UnsatisfiedLinkError : Native method not found: package. ClassName.stringFromJNI:()Ljava/lang/String;,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30149671/
我有一个旨在在 Linux 环境中运行的 java 应用程序,它是使用 Opencv 和 Eclipse - Ubuntu 14.04 开发的。它在 Eclipse 中运行良好,并在导出时生成一个 .
我有一个 Android 项目,它使用具有相互依赖关系的库: Android 应用程序依赖于以下原生库 模块 tess-2(包含 tesseract 和 leptonica) 模块 opencv4an
我正在开发一个需要使用.so库的项目(ubuntu 18.04),当我将java代码放在/src文件夹中时一切正常(我使用的是IntelliJ Idea),但是在我移动之后我的代码放入命名包(smut
我创建了一个使用 autohotkey.dll 库的 jar 文件。 Jar 在我的主电脑和笔记本电脑上运行顺利,但现在我尝试在新安装了 Windows 10 的电脑上使用它,但收到此错误: Exce
关闭。这个问题需要多问focused 。目前不接受答案。 想要改进此问题吗?更新问题,使其仅关注一个问题 editing this post . 已关闭 8 年前。 Improve this ques
我创建了一个使用 google or-tools 的 spring 应用程序。为此,我使用 System.loadLibrary("jniortools") 导入 jniortools。当我提供 .d
我正在尝试使用我下载的小程序。使用时出现以下错误 Can't load library 'friend'. java.lang.UnsatisfiedLinkError:no friend in ja
我知道捕获错误不是一个好的做法,但在这种情况下,这样做很重要。我正在尝试运行一个包含游戏一部分的 jar,但它给了我一个 unsatisfiedlink 错误,但这是有趣的部分:我正在使用这段代码:
我正在尝试创建Java软件,该软件允许我启动程序并通过ActiveXComponent对其进行控制。为了使用ActiveXCompnent,我下载了一个名为“ jacob-1.18”的JAR文件。当我
我已经完成了大部分GWT MVP风格的测试,而没有测试小部件。我希望能够构建更复杂的小部件并对其进行良好的测试,而无需使用GwtTestCase(缓慢)。 出于好奇,我尝试了一个非常简单的测试。给一个
我正在使用 Proycon 将 .class 反编译为 .java,在我的库目录中包含 jd-core-java-1.0.jar 文件,但是当我编译 Main 类时它抛出异常 Exception in
我正在编写一个使用JNI的程序,当我在我的计算机上运行它时它工作正常,但如果我尝试在另一台计算机上运行它,它会抛出UnsatisfiedLinkError,说它找不到依赖库。我使用 Eclipse,并
我正在使用 javacpp 从 Java 访问 cpp。 我已经尝试过文档中提供的示例 cpp代码: CompletableFuture futureInC(){ @StdFuture
Error is :Exception in thread "main" java.lang.UnsatisfiedLinkError: jpcap.JpcapCaptor.getDeviceLi
我正在尝试使用 JNI 向 Java 公开 C++ 功能。我试图首先显示一个简单的消息框,只是为了确保一切正常。但是,我得到了一个 UnsatisfiedLinkError 异常被抛出(当我调用函数时
尝试使用来自 here 的代码我试图合并这两个类,以便最终得到 ulaw 音频数据的 inputStream。所以我像这样编辑了 UlawEncoderInputStream: private Mic
我正在使用 Android Studio 3,并尝试在我的设备上使用 OpenCL。APK 编译失败: java.lang.UnsatisfiedLinkError: dlopen failed: l
我正在开发 SIP 基础应用程序来调用和接听电话我对一个开源项目进行了分析 Sipdroid.除此之外,我制作此应用程序以支持 g729 编解码器。该应用程序工作正常,但是当我修改应用程序的包名称时,
我知道这个问题已经被问过了,但我没有找到任何方法来阅读现有代码来找到解决我的问题的方法。我的一些应用程序用户对不同类型的 UnsatifiedLinkError 有经验: Caused by: jav
我在 Windows 7 中使用 IntelliJ,在最近对我的开发系统(不是设备)进行了突然更改后,我陷入了 UnsatisfiedLinkError 的困境。由 System.loadLibrar
我是一名优秀的程序员,十分优秀!