0
votes

In my Codenameone project, I am calling native libraty (andlib) without source code. It works good when it is in debug version but when it breaks when it's built with release option. Application starts but it breaks when native code is called.

It fails even if "android.enableProguard = false" build hint is used.

my java code is(it breaks on the last line of code):

final android.app.Activity ctx = com.codename1.impl.android.AndroidNativeUtil.getActivity();
Intent intent = new Intent(ctx, Pdf417ScanActivity.class); 

Pdf417MobiSettings sett = new Pdf417MobiSettings();
sett.setPdf417Enabled(true);
sett.setNullQuietZoneAllowed(true);
sett.setDecodeUSDriverLicenseData(true);
sett.setQrCodeEnabled(true);
sett.setDontShowDialog(true);
sett.setRemoveOverlayEnabled(true);
intent.putExtra(Pdf417ScanActivity.EXTRAS_SETTINGS, sett);

System.out.println("----- before startActivityForResult");

com.codename1.impl.android.AndroidNativeUtil.startActivityForResult(intent, new IntentResultListener() {

This is error log from logcat:

12-04 09:50:21.417: E/dalvikvm(31608): Class lookup Ljava/lang/NoClassDefFoundError; attempted while exception Ljava/lang/ExceptionInInitializerError; pending
12-04 09:50:21.437: E/dalvikvm(31608): VM aborting
12-04 09:50:28.324: E/dalvikvm(31677): Could not find class 'com.codename1.impl.android.AndroidTextureView', referenced from method com.codename1.impl.android.AndroidImplementation.initSurface
12-04 09:50:28.534: E/libEGL(31677): eglCreateWindowSurface  format=4
12-04 09:50:32.307: E/TvOut-Observer(182): SetOrientation
12-04 09:50:32.708: E/AutoRotationSettingButton(263): hr
12-04 09:50:34.309: E/FastDormancy(275):  before ======= ENTER DORMANCY =======

Instructions for using ProGuard with this native library are:

If you are using ProGuard, add the following lines to your application proguard-project.txt file

-keep class net.photopay.** { *; }

-keepclassmembers class net.photopay.** {
    *;
}

-keep class mobi.pdf417.** { *; }

-keepclassmembers class mobi.pdf417.** { 
    *; 
}

-dontwarn android.hardware.**

-dontwarn android.support.v4.**

Should these ProGuard instrucrions matter if I set "android.enableProguard = false" ?


We have created a simple test project with the library QRScanner.cn1lib (link is from the codename website). QRScanner.cn1lib is included in our project "lib" folder and we have a similar problem. It works fine in debug mode(scans qr code), and fails in release version(fails to scan and crashes). Build hit "android.enableProguard" is set to "false". Here is error log:

12-05 09:22:29.896: E/dalvikvm(13180): Could not find class 'com.codename1.impl.android.AndroidTextureView', referenced from method com.codename1.impl.android.AndroidImplementation.initSurface
12-05 09:22:31.508: E/TvOut-Observer(182): SetOrientation
12-05 09:22:31.668: E/AutoRotationSettingButton(263): hr
12-05 09:22:32.559: E/QualcommCameraHardware(122): Failed to get maximum zoom value...setting max zoom to zero
12-05 09:22:32.569: E/QualcommCameraHardware(122): native_set_ext_config E (cmd 46, param1 0 param2 0)
12-05 09:22:32.569: E/QualcommCameraHardware(122): native_set_ext_config E (cmd 5, param1 0 param2 0)
12-05 09:22:32.569: E/QualcommCameraHardware(122): native_set_ext_config E (cmd 11, param1 0 param2 0)
12-05 09:22:32.569: E/QualcommCameraHardware(122): native_set_ext_config E (cmd 9, param1 5 param2 0)
12-05 09:22:32.569: E/QualcommCameraHardware(122): native_set_ext_config E (cmd 12, param1 31 param2 0)
12-05 09:22:32.569: E/QualcommCameraHardware(122): native_set_ext_config E (cmd 13, param1 0 param2 0)
12-05 09:22:32.569: E/QualcommCameraHardware(122): native_set_ext_config E (cmd 13, param1 31 param2 0)
12-05 09:22:32.579: E/QualcommCameraHardware(122): native_set_ext_config E (cmd 3, param1 0 param2 0)
12-05 09:22:32.579: E/QualcommCameraHardware(122): #########################################SCENE_MODE : 0
12-05 09:22:32.579: E/QualcommCameraHardware(122): native_set_ext_config E (cmd 7, param1 0 param2 0)
12-05 09:22:32.579: E/QualcommCameraHardware(122): native_set_ext_config E (cmd 21, param1 0 param2 0)
12-05 09:22:32.579: E/QualcommCameraHardware(122): native_set_ext_config E (cmd 8, param1 1 param2 0)
12-05 09:22:32.579: E/QualcommCameraHardware(122): native_set_ext_config E (cmd 6, param1 5 param2 0)
12-05 09:22:32.589: E/QualcommCameraHardware(122): native_set_ext_config E (cmd 4, param1 10 param2 0)
12-05 09:22:32.589: E/QualcommCameraHardware(122): native_set_ext_config E (cmd 20, param1 0 param2 0)
12-05 09:22:32.589: E/QualcommCameraHardware(122): native_set_ext_config E (cmd 14, param1 4 param2 0)
12-05 09:22:32.589: E/QualcommCameraHardware(122): native_set_ext_config E (cmd 34, param1 0 param2 0)
12-05 09:22:32.609: E/ANDROID_DRM_TEST(122): getPlayerType return 4
12-05 09:22:32.619: E/AudioSink(122): AudioOutput(1180)
12-05 09:22:32.619: E/ANDROID_DRM_TEST(122):  setDataSource end status 0
12-05 09:22:32.679: E/MediaPlayer(122): message received msg=5, ext1=0, ext2=0
12-05 09:22:32.679: E/MediaPlayer(122): message received msg=1, ext1=0, ext2=0
12-05 09:22:32.679: E/ANDROID_DRM_TEST(122): getPlayerType return 4
12-05 09:22:32.679: E/AudioSink(122): AudioOutput(1181)
12-05 09:22:32.679: E/ANDROID_DRM_TEST(122):  setDataSource end status 0
12-05 09:22:32.729: E/MediaPlayer(122): message received msg=5, ext1=0, ext2=0
12-05 09:22:32.729: E/MediaPlayer(122): message received msg=1, ext1=0, ext2=0
12-05 09:22:32.729: E/OverlayLIB(122): [/dev/graphics/fb0] open - fd: 912
12-05 09:22:32.739: E/QualcommCameraHardware(122): native_set_ext_config E (cmd 46, param1 0 param2 0)
12-05 09:22:32.739: E/QualcommCameraHardware(122): native_set_ext_config E (cmd 5, param1 0 param2 0)
12-05 09:22:32.739: E/QualcommCameraHardware(122): #########################################SCENE_MODE : 0
12-05 09:22:32.739: E/QualcommCameraHardware(122): native_set_ext_config E (cmd 10, param1 0 param2 0)
12-05 09:22:32.739: E/QualcommCameraHardware(122): native_set_ext_config E (cmd 34, param1 0 param2 0)
12-05 09:22:32.759: E/ShotSingle(122): startPreview - mUseOverlay(1)
12-05 09:22:32.759: E/QualcommCameraHardware(122): native_set_ext_config E (cmd 23, param1 1 param2 0)
12-05 09:22:32.759: E/CAM_FD(122): [HCHYUN]ce147_video_config, sfd = 907
12-05 09:22:33.560: E/OverlayLIB(122): [/dev/graphics/fb0] open - fd: 912
12-05 09:22:33.570: E/QualcommCameraHardware(122): Start AF
12-05 09:22:33.570: E/QualcommCameraHardware(122): native_set_ext_config E (cmd 15, param1 0 param2 0)
12-05 09:22:33.690: E/AndroidRuntime(13180): FATAL EXCEPTION: main
12-05 09:22:33.690: E/AndroidRuntime(13180): java.lang.ExceptionInInitializerError
12-05 09:22:33.690: E/AndroidRuntime(13180):     at com.dm.zbar.android.scanner.ZBarScannerActivity.onPreviewFrame(ZBarScannerActivity.java:127)
12-05 09:22:33.690: E/AndroidRuntime(13180):     at android.hardware.Camera$EventHandler.handleMessage(Camera.java:590)
12-05 09:22:33.690: E/AndroidRuntime(13180):     at android.os.Handler.dispatchMessage(Handler.java:99)
12-05 09:22:33.690: E/AndroidRuntime(13180):     at android.os.Looper.loop(Looper.java:130)
12-05 09:22:33.690: E/AndroidRuntime(13180):     at android.app.ActivityThread.main(ActivityThread.java:3687)
12-05 09:22:33.690: E/AndroidRuntime(13180):     at java.lang.reflect.Method.invokeNative(Native Method)
12-05 09:22:33.690: E/AndroidRuntime(13180):     at java.lang.reflect.Method.invoke(Method.java:507)
12-05 09:22:33.690: E/AndroidRuntime(13180):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
12-05 09:22:33.690: E/AndroidRuntime(13180):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625)
12-05 09:22:33.690: E/AndroidRuntime(13180):     at dalvik.system.NativeStart.main(Native Method)
12-05 09:22:33.690: E/AndroidRuntime(13180): Caused by: java.lang.NoSuchFieldError: data
12-05 09:22:33.690: E/AndroidRuntime(13180):     at net.sourceforge.zbar.Image.init(Native Method)
12-05 09:22:33.690: E/AndroidRuntime(13180):     at net.sourceforge.zbar.Image.<clinit>(Unknown Source)
12-05 09:22:33.690: E/AndroidRuntime(13180):     ... 10 more
12-05 09:22:33.700: E/(182): Dumpstate > /data/log/dumpstate_app_error

This is the java code:

protected void onMain_ButtonScanAction(final Component c, ActionEvent event) {
        Form f = c.getComponentForm();
        final TextArea tra = findTextAreaResult(f);
        tra.setText("Wait for result ...");
        System.out.println("---- before QRScanner.scanQRCode");
        QRScanner.scanQRCode(new ScanResult() {
                    public void scanCompleted(String contents, String formatName, byte[] rawBytes) {
                        System.out.println("---- scanCompleted");
                        System.out.println("---- contents=" + contents);
                        tra.setText(contents);
                    }

                    public void scanCanceled() {
                        System.out.println("---- scanCompleted");
                        Dialog.show("QR Code", "scan Canceled", "OK", null); 
                    }

                    public void scanError(int errorCode, String message) {
                        System.out.println("---- scanCompleted");
                        Dialog.show("QR Code", "scan Error", "OK", null); 
                    }
                });
        }
}

these are keys(from properties file) required by QRScanner.cn1lib:

codename1.arg.android.xapplication=<activity android\:name\="com.dm.zbar.android.scanner.ZBarScannerActivity" android\:screenOrientation\="landscape" android\:label\="@string/app_name" />
codename1.arg.android.xpermissions=<uses-permission android\:name\="android.permission.CAMERA"/><uses-feature android\:name\="android.hardware.camera" android\:required\="false"/>
codename1.arg.android.proguard.Keep=-keep class net.sourceforge.zbar.** {*;}

Does anyone have any clue? Thanks!

1
Are you sure you set android.enableProguard = false correctly and didn't include spaces or other elements in the property. You didn't just type it into the properties file or something like that? Right? In what way does it fail? Do you have crash logs from DDMS or something to go on? - Shai Almog
I've entered android.enableProguard hint in NetBeans and there are no spaces.In properties file it looks like this:"codename1.arg.android.enableProguard=false". I have updated my question with crash logs and my java code. - Ivan Drago
Can you try now and see if it works? Looking at the logs its possible you ran into a separate problem related to a failed attempt at supporting Lollipop actionbar. - Shai Almog
I have tried it and it still doesn't work. The error from the error log is the same. I have updated my question with another example using .cn1lib library where we have the same problem: debug version works but release fails... - Ivan Drago
I've specifically tested the QRScanner in a release mode. Did you follow all the instructions he mentioned here: github.com/littlemonkeyltd/QRScanner Notice that there is a pretty clear exception in the initializer in this case which should help in tracking that. - Shai Almog

1 Answers

0
votes

It seems that enableProguard broke in a recent update to the Android SDK, we are trying to fix it but in the meantime I suggest using a more specific proguard condition.