keithwb
keithwb

Reputation: 81

Application closing once started

I finally got the code to compile, however it gets closed every time I start it. Can anyone advise me what is wrong?

Below is the manifest and the logcat and top half of the code in the activity.

this is a application project done by one coder. it is using native library. i had compiled the native library using cygwin. it is able to compiled successfully. for the error "could not load needed library 'libiconv.so' for 'libexif2.so' (load_library[1108]: Library 'libiconv.so' not found) 01-20 14:08:19.791", i had checked, these 2 files has been generated. is there any place else i need place the library file to?

<?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();

Upvotes: 0

Views: 3436

Answers (2)

yunzhi
yunzhi

Reputation: 11

If your are using android sdk more than 12,try to delete

<uses-feature android:required="true" android:name="android.hardware.usb.host"></uses-feature>

in manifest to test it,i once faced this problem on android 4.0 system.

Upvotes: 1

Yury
Yury

Reputation: 20936

It seems that the problem is that the compiler cannot find your so libraries. Is this your project or you just downloaded it from the Internet? If it is from the Internet then you should also check if this project uses native code (does it have smth like jni folder with .c, .cpp or .h files?). If yes, then you should at first build your native part and only after this you can make a build of your code.

Upvotes: 3

Related Questions