我终于得到了编译代码,但是每次启动它都会关闭。谁能告诉我什么是错的?
下面是清单以及活动中代码的logcat和上半部分。
这是一个由编码人员完成的应用程序项目。它使用的是本机库。我使用cygwin编译了本机库。它能够成功编译。对于错误“无法为'libexif2.so'加载所需的库'libiconv.so'(load_library [1108]:未找到库'libiconv.so')01-20 14:08:19.791”,我已经检查过,这些已生成2个文件。有什么地方我需要把库文件放到?
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.kos.agphoto2"
android:versionName="0.1"
android:versionCode="1">
<uses-feature android:required="true" android:name="android.hardware.usb.host"></uses-feature>
<uses-sdk android:minSdkVersion="12"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<application android:debuggable="true">
<activity android:name=".DetectCameraActivity" android:label="Detect Camera">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
<intent-filter>
<action android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED"/>
</intent-filter>
<meta-data android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED"
android:resource="@xml/device_filter" />
</activity>
</application>
</manifest>
> 01-20 14:08:19.761: DEBUG/dalvikvm(390): Trying to load lib > /data/data/com.kos.agphoto2/lib/libexif2.so 0x40642338 01-20 > 14:08:19.771: WARN/dalvikvm(390): Exception > Ljava/lang/UnsatisfiedLinkError; thrown while initializing > Lcom/kos/agphoto2/DetectCameraActivity; 01-20 14:08:19.771: > WARN/dalvikvm(390): Class init failed in newInstance call > (Lcom/kos/agphoto2/DetectCameraActivity;) 01-20 14:08:19.771: > DEBUG/AndroidRuntime(390): Shutting down VM 01-20 14:08:19.771: > WARN/dalvikvm(390): threadid=1: thread exiting with uncaught exception > (group=0x40014760) 01-20 14:08:19.791: ERROR/AndroidRuntime(390): > FATAL EXCEPTION: main 01-20 14:08:19.791: ERROR/AndroidRuntime(390): > java.lang.ExceptionInInitializerError 01-20 14:08:19.791: > ERROR/AndroidRuntime(390): at > java.lang.Class.newInstanceImpl(Native Method) 01-20 14:08:19.791: > ERROR/AndroidRuntime(390): at > java.lang.Class.newInstance(Class.java:1301) 01-20 14:08:19.791: > ERROR/AndroidRuntime(390): at > android.app.Instrumentation.newActivity(Instrumentation.java:1022) > 01-20 14:08:19.791: ERROR/AndroidRuntime(390): at > android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1663) > 01-20 14:08:19.791: ERROR/AndroidRuntime(390): at > android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1764) > 01-20 14:08:19.791: ERROR/AndroidRuntime(390): at > android.app.ActivityThread.access$1500(ActivityThread.java:122) 01-20 > 14:08:19.791: ERROR/AndroidRuntime(390): at > android.app.ActivityThread$H.handleMessage(ActivityThread.java:1002) > 01-20 14:08:19.791: ERROR/AndroidRuntime(390): at > android.os.Handler.dispatchMessage(Handler.java:99) 01-20 > 14:08:19.791: ERROR/AndroidRuntime(390): at > android.os.Looper.loop(Looper.java:132) 01-20 14:08:19.791: > ERROR/AndroidRuntime(390): at > android.app.ActivityThread.main(ActivityThread.java:4025) 01-20 > 14:08:19.791: ERROR/AndroidRuntime(390): at > java.lang.reflect.Method.invokeNative(Native Method) 01-20 > 14:08:19.791: ERROR/AndroidRuntime(390): at > java.lang.reflect.Method.invoke(Method.java:491) 01-20 14:08:19.791: > ERROR/AndroidRuntime(390): at > com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:841) > 01-20 14:08:19.791: ERROR/AndroidRuntime(390): at > com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599) 01-20 > 14:08:19.791: ERROR/AndroidRuntime(390): at > dalvik.system.NativeStart.main(Native Method) 01-20 14:08:19.791: > ERROR/AndroidRuntime(390): Caused by: java.lang.UnsatisfiedLinkError: > Cannot load library: link_image[1966]: 32 could not load needed > library 'libiconv.so' for 'libexif2.so' (load_library[1108]: Library > 'libiconv.so' not found) 01-20 14:08:19.791: > ERROR/AndroidRuntime(390): at > java.lang.Runtime.loadLibrary(Runtime.java:430) 01-20 14:08:19.791: > ERROR/AndroidRuntime(390): at > java.lang.System.loadLibrary(System.java:554) 01-20 14:08:19.791: > ERROR/AndroidRuntime(390): at > com.kos.agphoto2.api.LibrariesHelper.loadNativeLibraries(LibrariesHelper.java:42) > 01-20 14:08:19.791: ERROR/AndroidRuntime(390): at > com.kos.agphoto2.DetectCameraActivity.(DetectCameraActivity.java:78) > 01-20 14:08:19.791: ERROR/AndroidRuntime(390): ... 15 more 01-20 > 14:08:19.801: WARN/ActivityManager(81): Force finishing activity > com.kos.agphoto2/.DetectCameraActivity 01-20 14:08:20.315: > WARN/ActivityManager(81): Activity pause timeout for > ActivityRecord{40b92fe8 com.kos.agphoto2/.DetectCameraActivity} 01-20 > 14:08:20.351: INFO/ActivityManager(81): Displayed > com.android.launcher/com.android.launcher2.Launcher: +32s438ms 01-20 > 14:08:24.411: DEBUG/dalvikvm(81): GC_CONCURRENT freed 207K, 15% free > 10682K/12487K, paused 5ms+5ms
public class DetectCameraActivity extends Activity {
static {
LibrariesHelper.loadNativeLibraries();
}
private GPContext c;
private ProgressDialog pd;
private Handler h;
private static final String DETECTCAMERA = "DETECTCAMERA";
private PendingIntent mPermissionIntent;
private UsbManager mUsbManager;
private UsbInterface mUsbIntf;
private UsbDeviceConnection mConnection;
private boolean mUsbConnected = false; // We only connect to one camera at a time. Ignore additional cameras
private boolean mForceClaim = true;
private static final String ACTION_USB_PERMISSION = "com.kos.agphoto2.USB_PERMISSION";
private final BroadcastReceiver mUsbReceiver = new BroadcastReceiver() {
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if (ACTION_USB_PERMISSION.equals(action) || UsbManager.ACTION_USB_DEVICE_ATTACHED.equals(action)) {
synchronized (this) {
UsbDevice device = (UsbDevice)intent.getParcelableExtra(UsbManager.EXTRA_DEVICE);
if (intent.getBooleanExtra(UsbManager.EXTRA_PERMISSION_GRANTED, false)) {
if(!mUsbConnected && device != null){
//call method to set up device communication
claimDevice(device);
mUsbConnected = true;
}
}
else {
Log.d(DETECTCAMERA, "permission denied for device " + device);
}
}
}
if (UsbManager.ACTION_USB_DEVICE_DETACHED.equals(action)) {
UsbDevice device = (UsbDevice)intent.getParcelableExtra(UsbManager.EXTRA_DEVICE);
if (mUsbConnected && device != null) {
// call your method that cleans up and closes communication with the device
cleanUpDevices();
mUsbConnected = false;
}
}
}
};
private void claimDevice(UsbDevice device) {
Log.d(DETECTCAMERA, "Claiming device: " + device.toString());
mUsbIntf = device.getInterface(0);
// Only need following line if using Java to communicate
// UsbEndpoint endpoint = mUsbIntf.getEndpoint(0);
mConnection = mUsbManager.openDevice(device);
if(mConnection.claimInterface(mUsbIntf, mForceClaim))
Log.d(DETECTCAMERA,"Interface succesfully claimed!");
}
private void cleanUpDevices() {
if(mUsbConnected && mConnection!=null) {
mConnection.close();
if(mUsbIntf!=null) {
mConnection.releaseInterface(mUsbIntf);
}
}
}
@Override
public void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//Set up USB stuff
mUsbManager = (UsbManager) getSystemService(android.content.Context.USB_SERVICE);
mPermissionIntent = PendingIntent.getBroadcast(this, 0, new Intent(ACTION_USB_PERMISSION), 0);
IntentFilter filter = new IntentFilter(ACTION_USB_PERMISSION);
registerReceiver(mUsbReceiver, filter);
//Iterate over connect USB devices, check if any match our intent filter
HashMap<String, UsbDevice> deviceList = mUsbManager.getDeviceList();
Iterator<UsbDevice> deviceIterator = deviceList.values().iterator();
//TODO: get list of device filters from resource file
// XmlResourceParser xrp = getResources().getXml(R.xml.device_filter);
while(deviceIterator.hasNext()){
UsbDevice device = deviceIterator.next();
//TODO: compare device to list of device filters
// if( device.getVendorId() )
mUsbManager.requestPermission(device, mPermissionIntent);
}
setContentView(R.layout.detect_camera);
// getPanel().setMovementMethod(new ScrollingMovementMethod());
h = new Handler() {
@Override
public void handleMessage(final Message msg) {
if (msg.obj instanceof String) {
final String s = (String) (msg.obj);
getPanel().setText(s);
getPanel().scrollTo(0, 0);
}
pd.dismiss();
}
};
c = GPContextImpl.createNew();
答案 0 :(得分:3)
似乎问题是编译器找不到你的库。这是您的项目还是您刚从互联网上下载的?如果是来自互联网,那么你还应该检查这个项目是否使用本机代码(它是否具有像.c,.cpp或.h文件的jni文件夹?)。如果是,那么您应该首先构建您的原生部分,然后才能构建您的代码。
答案 1 :(得分:1)
如果您使用的是超过12的android sdk,请尝试删除
<uses-feature android:required="true" android:name="android.hardware.usb.host"></uses-feature>
在清单中测试它,我曾经在android 4.0系统上遇到过这个问题。