【发布时间】:2015-03-29 07:04:53
【问题描述】:
我的第一次清理和构建出现此错误:
make: *** No rule to make target `SpecProj_scd.mk'. Stop.
第二次构建,错误被删除。 请注意,ndk-build,构建良好。
所以我在我的实际设备(平板电脑)上运行该项目,但应用程序崩溃了。
LogCat:
01-29 16:48:48.081: E/Trace(3766): error opening trace file: No such file or directory (2)
01-29 16:48:48.081: D/jdwp(3766): sendBufferedRequest : len=0x39
01-29 16:48:48.110: D/dalvikvm(3766): open_cached_dex_file : /data/app/com.dece.specproj-2.apk /data/dalvik-cache/data@app@com.dece.specproj-2.apk@classes.dex
01-29 16:48:48.117: D/ActivityThread(3766): BIND_APPLICATION handled : 0 / AppBindData{appInfo=ApplicationInfo{42436e88 com.dece.specproj}}
01-29 16:48:48.128: W/dalvikvm(3766): Exception Ljava/lang/UnsatisfiedLinkError; thrown while initializing Lcom/dece/specproj/MainActivity;
01-29 16:48:48.128: W/dalvikvm(3766): Class init failed in newInstance call (Lcom/dece/specproj/MainActivity;)
01-29 16:48:48.128: D/AndroidRuntime(3766): Shutting down VM
01-29 16:48:48.128: W/dalvikvm(3766): threadid=1: thread exiting with uncaught exception (group=0x41e17908)
01-29 16:48:48.137: E/AndroidRuntime(3766): FATAL EXCEPTION: main
01-29 16:48:48.137: E/AndroidRuntime(3766): java.lang.ExceptionInInitializerError
01-29 16:48:48.137: E/AndroidRuntime(3766): at java.lang.Class.newInstanceImpl(Native Method)
01-29 16:48:48.137: E/AndroidRuntime(3766): at java.lang.Class.newInstance(Class.java:1319)
01-29 16:48:48.137: E/AndroidRuntime(3766): at android.app.Instrumentation.newActivity(Instrumentation.java:1053)
01-29 16:48:48.137: E/AndroidRuntime(3766): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2099)
01-29 16:48:48.137: E/AndroidRuntime(3766): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2211)
01-29 16:48:48.137: E/AndroidRuntime(3766): at android.app.ActivityThread.access$600(ActivityThread.java:149)
01-29 16:48:48.137: E/AndroidRuntime(3766): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1300)
01-29 16:48:48.137: E/AndroidRuntime(3766): at android.os.Handler.dispatchMessage(Handler.java:99)
01-29 16:48:48.137: E/AndroidRuntime(3766): at android.os.Looper.loop(Looper.java:153)
01-29 16:48:48.137: E/AndroidRuntime(3766): at android.app.ActivityThread.main(ActivityThread.java:4987)
01-29 16:48:48.137: E/AndroidRuntime(3766): at java.lang.reflect.Method.invokeNative(Native Method)
01-29 16:48:48.137: E/AndroidRuntime(3766): at java.lang.reflect.Method.invoke(Method.java:511)
01-29 16:48:48.137: E/AndroidRuntime(3766): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:821)
01-29 16:48:48.137: E/AndroidRuntime(3766): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:584)
01-29 16:48:48.137: E/AndroidRuntime(3766): at dalvik.system.NativeStart.main(Native Method)
01-29 16:48:48.137: E/AndroidRuntime(3766): Caused by: java.lang.UnsatisfiedLinkError: Couldn't load hellojni: findLibrary returned null
01-29 16:48:48.137: E/AndroidRuntime(3766): at java.lang.Runtime.loadLibrary(Runtime.java:365)
01-29 16:48:48.137: E/AndroidRuntime(3766): at java.lang.System.loadLibrary(System.java:535)
01-29 16:48:48.137: E/AndroidRuntime(3766): at com.dece.specproj.MainActivity.<clinit>(MainActivity.java:13)
01-29 16:48:48.137: E/AndroidRuntime(3766): ... 15 more
所以我确保我的所有目录都正确添加到环境变量 PATH 以及 Eclipse 中的 PATH,即我的 MinGW bin、MinGW msys bin、cygwin bin、android-ndk 以及 android- sdk ...我认为它们都添加正确,所以错误仍然出现。
我不确定是什么导致了这些问题,因为我是 Android NDK 的新手,所以我会发布我认为可能在其中起作用的内容。
Android.mk
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := SpecProj
LOCAL_SRC_FILES := hellojni.c
include $(BUILD_SHARED_LIBRARY)
hellojni.c
#include <string.h>
#include <jni.h>
jstring Java_com_dece_MainActivity_stringFromJNI(JNIEnv* env,jobject thiz)
{
return (*env)->NewStringUTF(env, "Hello from JNI !");
}
主要活动
package com.dece.specproj;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
public class MainActivity extends ActionBarActivity {
public native String stringFromJNI();
static
{
System.loadLibrary("hellojni");
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
activity_main
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.dece.specproj.MainActivity" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_world" />
</RelativeLayout>
AndroidManifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.dece.specproj"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="21" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme">
<activity
android:name=".MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
【问题讨论】:
标签: eclipse android-ndk makefile