DroidNinja / Android-FilePicker

Photopicker and document picker for android
https://arunsharma.me/blog/integrate-android-file-picker-photopicker-document-picker-android/
2.7k stars 557 forks source link

java.lang.NullPointerException: Attempt to invoke virtual method 'void android.support.v7.widget.SearchView.setOnQueryTextListener(android.support.v7.widget.SearchView$c)' on a null object reference #176

Open KhanStan99 opened 6 years ago

KhanStan99 commented 6 years ago

I encountered this problem in latest library 2.1.5. When i provide permission and picker loads this error occurs.

build.gradle implementation 'com.droidninja:filepicker:2.1.5'

Photo Picker Code:

private void initializePhotoPicker() {
        FilePickerBuilder.getInstance().setMaxCount(1)
                .setSelectedFiles(filePaths)
                .setActivityTheme(R.style.LibAppTheme)
                .pickFile(this);
    }

File Picker Code:

FilePickerBuilder.getInstance().setMaxCount(1)
                .setSelectedFiles(resumeFilePath)
                .setActivityTheme(R.style.LibAppTheme)
                .pickFile(this);

It was working fine in debug APK, but when i put it into PlayStore it gives me this error. (Same Code)

zeevy commented 6 years ago

Hello check this

156

KhanStan99 commented 6 years ago

Hi @zeevy , I am handling that case on my side. when user haven't selected anything my app works fine. but this error is different. Event after providing permissions the app crashes.

Edit: And it is also very weird, It is working fine when i install debug APK from android studio but when i test after uploading on play store when it test i face this issue.

zeevy commented 6 years ago

It may work in debug build because Proguard may be disabled in debug build. Make sure you tested the release apk before pushing it to play store.

I face two problem with this lib

  1. Permissions (it needs both read/write permissions)
  2. This issue (thankfully i was able to solve this using proguard rules)

To make sure its proguard issue you can generate the signed release apk with out proguard enabled. And install the apk on your phone and test it.

zeevy commented 6 years ago

additionally you can try adding all these proguard rule which are mentioned in the Readme.md

# Glide
-keep public class * implements com.bumptech.glide.module.GlideModule
-keep public enum com.bumptech.glide.load.resource.bitmap.ImageHeaderParser$** {
    **[] $VALUES;
    public *;
}
# support-v7-appcompat
-keep public class android.support.v7.widget.** { *; }
-keep public class android.support.v7.internal.widget.** { *; }
-keep public class android.support.v7.internal.view.menu.** { *; }
-keep public class * extends android.support.v4.view.ActionProvider {
    public <init>(android.content.Context);
}
# support-design
-dontwarn android.support.design.**
-keep class android.support.design.** { *; }
-keep interface android.support.design.** { *; }
-keep public class android.support.design.R$* { *; }
KhanStan99 commented 6 years ago

Hi @zeevy , I have added these lines in proguard and enabled in debug. now it gives me this error. It does not even open the application.

java.lang.RuntimeException: Unable to get provider droidninja.filepicker.utils.FilePickerProvider: java.lang.ClassNotFoundException: Didn't find class "droidninja.filepicker.utils.FilePickerProvider" on path: DexPathList[[zip file "/data/app/com.scoratech.scoraxchange.devbuild-6T40M2EdkMMAGlAoAw_yNQ==/base.apk", zip file "/data/app/com.scoratech.scoraxchange.devbuild-6T40M2EdkMMAGlAoAw_yNQ==/split_lib_dependencies_apk.apk", zip file "/data/app/com.scoratech.scoraxchange.devbuild-6T40M2EdkMMAGlAoAw_yNQ==/split_lib_resources_apk.apk", zip file "/data/app/com.scoratech.scoraxchange.devbuild-6T40M2EdkMMAGlAoAw_yNQ==/split_lib_slice_0_apk.apk", zip file "/data/app/com.scoratech.scoraxchange.devbuild-6T40M2EdkMMAGlAoAw_yNQ==/split_lib_slice_1_apk.apk", zip file "/data/app/com.scoratech.scoraxchange.devbuild-6T40M2EdkMMAGlAoAw_yNQ==/split_lib_slice_2_apk.apk", zip file "/data/app/com.scoratech.scoraxchange.devbuild-6T40M2EdkMMAGlAoAw_yNQ==/split_lib_slice_3_apk.apk", zip file "/data/app/com.scoratech.scoraxchange.devbuild-6T40M2EdkMMAGlAoAw_yNQ==/split_lib_slice_4_apk.apk", zip file "/data/app/com.scoratech.scoraxchange.devbuild-6T40M2EdkMMAGlAoAw_yNQ==/split_lib_slice_5_apk.apk", zip file "/data/app/com.scoratech.scoraxchange.devbuild-6T40M2EdkMMAGlAoAw_yNQ==/split_lib_slice_6_apk.apk", zip file "/data/app/com.scoratech.scoraxchange.devbuild-6T40M2EdkMMAGlAoAw_yNQ==/split_lib_slice_7_apk.apk", zip file "/data/app/com.scoratech.scoraxchange.devbuild-6T40M2EdkMMAGlAoAw_yNQ==/split_lib_slice_8_apk.apk", zip file "/data/app/com.scoratech.scoraxchange.devbuild-6T40M2EdkMMAGlAoAw_yNQ==/split_lib_slice_9_apk.apk"],nativeLibraryDirectories=[/data/app/com.scoratech.scoraxchange.devbuild-6T40M2EdkMMAGlAoAw_yNQ==/lib/arm64, /system/lib64, /system/vendor/lib64]]

zeevy commented 6 years ago

Have you tried? minifyEnabled false shrinkResources false

in buildTypes release

KhanStan99 commented 6 years ago

Oh those both are enabled. should i disabled in both release and debug?

zeevy commented 6 years ago

Yes disable and check


From: Hidayat Ullah Khan notifications@github.com Sent: Tuesday, July 24, 2018 10:44:52 AM To: DroidNinja/Android-FilePicker Cc: zeevy; Mention Subject: Re: [DroidNinja/Android-FilePicker] java.lang.NullPointerException: Attempt to invoke virtual method 'void android.support.v7.widget.SearchView.setOnQueryTextListener(android.support.v7.widget.SearchView$c)' on a null object reference (#176)

Oh those both are enabled. should i disabled in both release and debug?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://github.com/DroidNinja/Android-FilePicker/issues/176#issuecomment-407283693, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AA5W0WbgOQaqtrQbgnToESXoNt-pm_WLks5uJq1MgaJpZM4VQmEJ.

KhanStan99 commented 6 years ago

Yes, it is working fine after disabling those 2.

zeevy commented 6 years ago

That means, you probably misplaced your proguard rules. You need to add proper rules in proper place

zeevy commented 6 years ago

This is my build.gradle file which is working fine.

https://github.com/zeevy/grblcontroller/blob/master/app/build.gradle

KhanStan99 commented 6 years ago

Ok thanks 👍👍

mssaravanan commented 5 years ago

Again same issue in latest version2.2.0 I tried all above ideas