Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Android 11 Crash #127

Open
OPunktSchmidt opened this issue Sep 7, 2020 · 16 comments
Open

[BUG] Android 11 Crash #127

OPunktSchmidt opened this issue Sep 7, 2020 · 16 comments

Comments

@OPunktSchmidt
Copy link

OPunktSchmidt commented Sep 7, 2020

This library seems to crash on Android 11. Is it planned to fix this? I dont get this error on other Android Versions

E/AndroidRuntime: FATAL EXCEPTION: main
    java.lang.NullPointerException: Attempt to get length of null array
        at com.codekidlabs.storagechooser.fragments.ChooserDialogFragment.populateList(ChooserDialogFragment.java:262)
        at com.codekidlabs.storagechooser.fragments.ChooserDialogFragment.initListView(ChooserDialogFragment.java:115)
        at com.codekidlabs.storagechooser.fragments.ChooserDialogFragment.getLayout(ChooserDialogFragment.java:85)
        at com.codekidlabs.storagechooser.fragments.ChooserDialogFragment.onCreateDialog(ChooserDialogFragment.java:300)
        at android.app.DialogFragment.onGetLayoutInflater(DialogFragment.java:417)
        at android.app.Fragment.performGetLayoutInflater(Fragment.java:1322)
        at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1303)
        at android.app.FragmentManagerImpl.addAddedFragments(FragmentManager.java:2431)
        at android.app.FragmentManagerImpl.executeOpsTogether(FragmentManager.java:2210)
        at android.app.FragmentManagerImpl.removeRedundantOperationsAndExecute(FragmentManager.java:2166)
        at android.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:2067)
        at android.app.FragmentManagerImpl$1.run(FragmentManager.java:742)
        at android.os.Handler.handleCallback(Handler.java:938)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loop(Looper.java:223)
        at android.app.ActivityThread.main(ActivityThread.java:7656)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
@xiyurain
Copy link

Same problem : (

@oluwabajio
Copy link

Same Problem Kindly fix

@nikeshkumarbedia
Copy link

Same problem with android 11. Kindly update on this.

@mveroukis
Copy link

+1. My app also crashes with the exact same exception on Android 11. It's possible that the bug is in Android 11, I feel it's a bit of a buggy release, but still, it would be nice to have a work around or something. Thanks.

@NoelChew
Copy link

NoelChew commented Dec 6, 2020

+1

@mveroukis
Copy link

Looks like someone has a potential fix: sfilmak@c43a6b5

@OPunktSchmidt
Copy link
Author

Has anyone found an alternative for this library? I don't think the bug will be fixed in the near future.

@mveroukis
Copy link

mveroukis commented Dec 9, 2020

No need for an alternative. Someone else (sfilmak) fixed it. I forked his fork, tagged it and created a release for it. Since the original library uses jitpack, it's really easy to switch over to use your own fork of it. I just changed out:
com.github.codekidX:storage-chooser:2.0.4.4

and replaced it with:
com.github.mveroukis:storage-chooser:2.0.4.4a

The "a" at the end is my own tag, otherwise it would continue using the same version as the original. Now my app works in Android 11. As a bonus, it also uses newer versions of it's dependencies and targets API 30.

@NoelChew
Copy link

Good idea @mveroukis
The commit sfilmak@c43a6b5 contains other changes that broke my build.
I have forked and uploaded a commit with the only change that fixes the crash on Android 11 devices.
Here's the my version:

NoelChew@f0ffc9c

implementation 'com.github.noelchew:storage-chooser:2.0.4.4a'

@1stmetro
Copy link

I did manage to get the original code working with the external drive, a bit of a hack but its working ok for me.

I did step back for API 28 as there wasn't much point going to 29 or 30 due to scoped storage and this version of the app isnt going on google play so the api version doesnt matter.

If anyone is interested i can post the hack and maybe someone will improve upon it, it was a quick mod to the existing code.

@Shabinder
Copy link

Updated Dependencies, Optimised and compressed Resources and New Publishing Plugin

implementation("com.github.shabinder:storage-chooser:2.0.4.45")

@mendhak
Copy link

mendhak commented Sep 20, 2021

FWIW I've also got a fork of this repo, with some additional fixes and changes

  • Added a generic file icon for unknown file types
  • Use folder icon only for folders (the library was using a folder icon for unknown file types)
  • Show SD Card on Android 11 ( bug - Android 11 has restrictions on /storage so I'm using getExternalFilesDirs)
  • Fix for crash on Android 11 (same as the topic of this thread)

If anyone wants:

implementation 'com.github.mendhak:storage-chooser:2.0.4.4b'

@kollabz
Copy link

kollabz commented Feb 6, 2022

Hi. @mendhak , i use your 'com.github.mendhak:storage-chooser:2.0.4.4b' and it's work good for open 'ChooserDialogFragment'.
But if i use 'customFilter' or 'filter' in chooser builder, I have error at 'UniversalFileFilter.java' and 'SecondaryChooserFragment.java'.

code:

    Content c = new Content();
    c.setInternalStorageText(getString(R.string.DIALOG_STORAGE_TEXT));
    c.setCancelLabel(getString(R.string.DIALOG_CANCEL));
    c.setSelectLabel(getString(R.string.DIALOG_SELECT));
    c.setOverviewHeading(getString(R.string.DIALOG_OVERVIEW_HEADING_IMPORT));

    ArrayList<String> formats = new ArrayList<>();
    formats.add("txt");

    builder.withActivity(this)
            .withFragmentManager(getFragmentManager())
            .setMemoryBarHeight(1.5f)
            .customFilter(formats)
            .withContent(c)
            .withMemoryBar(true)
            .allowCustomPath(true)
            .showHidden(true)
            .hideFreeSpaceLabel(true)
            .setType(StorageChooser.FILE_PICKER);
    chooser = builder.build();

log:
java.lang.RuntimeException: An error occurred while executing doInBackground()
at android.os.AsyncTask$4.done(AsyncTask.java:415)
at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:383)
at java.util.concurrent.FutureTask.setException(FutureTask.java:252)
at java.util.concurrent.FutureTask.run(FutureTask.java:271)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:305)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
at java.lang.Thread.run(Thread.java:923)
Caused by: java.lang.NullPointerException
at java.util.Objects.requireNonNull(Objects.java:220)
at com.codekidlabs.storagechooser.filters.UniversalFileFilter.findInDirectory(UniversalFileFilter.java:98)
at com.codekidlabs.storagechooser.filters.UniversalFileFilter.findInDirectory(UniversalFileFilter.java:121)
at com.codekidlabs.storagechooser.filters.UniversalFileFilter.accept(UniversalFileFilter.java:53)
at java.io.File.listFiles(File.java:1300)
at com.codekidlabs.storagechooser.fragments.SecondaryChooserFragment$FileFilterTask.doInBackground(SecondaryChooserFragment.java:822)
at com.codekidlabs.storagechooser.fragments.SecondaryChooserFragment$FileFilterTask.doInBackground(SecondaryChooserFragment.java:796)
at android.os.AsyncTask$3.call(AsyncTask.java:394)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:305) 
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167) 
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641) 
at java.lang.Thread.run(Thread.java:923) 

i try it on 'Android 11, Api30, Pixel 2(or3) ' in emulator and 'Android 11, Knox Api33, One UI3.1' in device

Maybe I'm doing something wrong(
Can you help me please?

mendhak added a commit to mendhak/storage-chooser that referenced this issue Feb 6, 2022
@mendhak
Copy link

mendhak commented Feb 6, 2022

@kollabz this looks Android 11 related as well. dir.listFiles() was returning null so this code block was throwing an exception.

I've added a check for length so it should be better now.

Do you want to try out the specific commit. If you say it's OK I could give it a tag.

implementation 'com.github.mendhak:storage-chooser:1715784d34'

@kollabz
Copy link

kollabz commented Feb 7, 2022

@mendhak, i have no error with 'customFilter' or 'filter' in chooser builder, but i don't see any files in the selected directory. It's empy. (
Maybe something wrong with adapter? Can you help me with it please?

i try it on 'Android 11, Api30, Pixel 2(or3) ' in emulator and 'Android 11, Knox Api33, One UI3.1' in device.
on 'Android 9, Api28 ' in device it work good

@mendhak
Copy link

mendhak commented Feb 7, 2022

@kollabz two things I can think of. First is obviously you'll want to make sure there are some files that match the filter, obviously. Second is you'll need to make sure your app has permissions, see here. One thing I noticed, despite permissions, I couldn't filter anything under /emulated/0/Android/data where all the app specific files are. I could play around at the top level like /emulated/0/Documents.

Anyway I did a test I filtered to show just "csv" files and I was get this. You can see I copied your code minus the withActivity and withContent. I tried on Android 11 and 12.

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

10 participants