Android-FilePicker icon indicating copy to clipboard operation
Android-FilePicker copied to clipboard

App crash when try to Pick a File when I am using 28.0.0 (compileSdkversion & targetSdkVersion)

Open crismaver1993 opened this issue 7 years ago • 30 comments

capture

Its version do the application crash -> compileSdkVersion 28 buildToolsVersion '28.0.3' targetSdkVersion 28

-> If I downgrade it to 27

compileSdkVersion 27 buildToolsVersion '27.0.3' targetSdkVersion 27

It works perfectly

crismaver1993 avatar Oct 03 '18 14:10 crismaver1993

Same error with me. I rolled back to 27.1.1 to make it work. Hope he fixes this ASAP.

KhanStan99 avatar Oct 04 '18 08:10 KhanStan99

Only file picker crashes. Photo picker works fine for me.

KhanStan99 avatar Oct 04 '18 08:10 KhanStan99

I have the same issue.

datMaster avatar Oct 10 '18 10:10 datMaster

Change compileSdkVersion to version 28 and then override method createDocumentType of DocScannerTask.java like this

private HashMap<FileType, List<Document>> createDocumentType(ArrayList<Document> documents) {
    HashMap<FileType, List<Document>> documentMap = new HashMap<>();

    for (final FileType fileType : fileTypes) {
      ArrayList<Document> documentListFilteredByType = new ArrayList<>();
      for (Document doc: documents) {
        if (doc.isThisType(fileType.extensions)) {
          documentListFilteredByType.add(doc);
        }
      }
      if (comparator != null) Collections.sort(documentListFilteredByType, comparator);
      documentMap.put(fileType, documentListFilteredByType);
    }

    return documentMap;
  }

datMaster avatar Oct 10 '18 11:10 datMaster

Change compileSdkVersion to version 28 and then override method createDocumentType of DocScannerTask.java like this

private HashMap<FileType, List<Document>> createDocumentType(ArrayList<Document> documents) {
    HashMap<FileType, List<Document>> documentMap = new HashMap<>();

    for (final FileType fileType : fileTypes) {
      ArrayList<Document> documentListFilteredByType = new ArrayList<>();
      for (Document doc: documents) {
        if (doc.isThisType(fileType.extensions)) {
          documentListFilteredByType.add(doc);
        }
      }
      if (comparator != null) Collections.sort(documentListFilteredByType, comparator);
      documentMap.put(fileType, documentListFilteredByType);
    }

    return documentMap;
  }

Sorry man! I was a little bit busy! I could not reply beofre. I will try it! So, Should I do a Fork?

crismaver1993 avatar Oct 10 '18 12:10 crismaver1993

Change compileSdkVersion to version 28 and then override method createDocumentType of DocScannerTask.java like this

private HashMap<FileType, List<Document>> createDocumentType(ArrayList<Document> documents) {
    HashMap<FileType, List<Document>> documentMap = new HashMap<>();

    for (final FileType fileType : fileTypes) {
      ArrayList<Document> documentListFilteredByType = new ArrayList<>();
      for (Document doc: documents) {
        if (doc.isThisType(fileType.extensions)) {
          documentListFilteredByType.add(doc);
        }
      }
      if (comparator != null) Collections.sort(documentListFilteredByType, comparator);
      documentMap.put(fileType, documentListFilteredByType);
    }

    return documentMap;
  }

Sorry man! I was a little bit busy! I could not reply beofre. I will try it! So, Should I do a Fork?

Yes, need to make fork. Also, you should use support library version 28.0.0

datMaster avatar Oct 10 '18 14:10 datMaster

Change compileSdkVersion to version 28 and then override method createDocumentType of DocScannerTask.java like this

private HashMap<FileType, List<Document>> createDocumentType(ArrayList<Document> documents) {
    HashMap<FileType, List<Document>> documentMap = new HashMap<>();

    for (final FileType fileType : fileTypes) {
      ArrayList<Document> documentListFilteredByType = new ArrayList<>();
      for (Document doc: documents) {
        if (doc.isThisType(fileType.extensions)) {
          documentListFilteredByType.add(doc);
        }
      }
      if (comparator != null) Collections.sort(documentListFilteredByType, comparator);
      documentMap.put(fileType, documentListFilteredByType);
    }

    return documentMap;
  }

Did you add something else? I put your code it is ok! But I having issues with Predicate<T> I already imported it but it doesn know .apply function inside of FilePickerUtils

`public static <T> Collection<T> filter(Collection<T> target, Predicate<T> predicate) {
        Collection<T> result = new ArrayList<T>();
        for (T element : target) {
            if (predicate**.apply**(element)) {
                result.add(element);
            }
        }
        return result;
    }`

crismaver1993 avatar Oct 16 '18 12:10 crismaver1993

Change compileSdkVersion to version 28 and then override method createDocumentType of DocScannerTask.java like this

private HashMap<FileType, List<Document>> createDocumentType(ArrayList<Document> documents) {
    HashMap<FileType, List<Document>> documentMap = new HashMap<>();

    for (final FileType fileType : fileTypes) {
      ArrayList<Document> documentListFilteredByType = new ArrayList<>();
      for (Document doc: documents) {
        if (doc.isThisType(fileType.extensions)) {
          documentListFilteredByType.add(doc);
        }
      }
      if (comparator != null) Collections.sort(documentListFilteredByType, comparator);
      documentMap.put(fileType, documentListFilteredByType);
    }

    return documentMap;
  }

Did you add something else? I put your code it is ok! But I having issues with Predicate I already imported it but it doesn know .apply function inside of FilePickerUtils

`public static <T> Collection<T> filter(Collection<T> target, Predicate<T> predicate) {
        Collection<T> result = new ArrayList<T>();
        for (T element : target) {
            if (predicate**.apply**(element)) {
                result.add(element);
            }
        }
        return result;
    }`

You can delete method 'filter'. It is doesn't need after changes in DocScannerTask class.

datMaster avatar Oct 19 '18 05:10 datMaster

try out new version 2.2.0 with androidx

DroidNinja avatar Oct 20 '18 19:10 DroidNinja

I've updated the library to 2.2.0 and my project to androidx as well but i was still getting a crash when i use the pickFile option. I've resolved the issue by adding .sortDocumentsBy(SortingTypes.name) to the builder method though. Using .sortDocumentsBy(SortingTypes.none) also caused a crash.

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.world.lynkedworld/droidninja.filepicker.FilePickerActivity}: java.lang.IllegalStateException: PickerManager.sortingType.comparator must not be null at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2416) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476) at android.app.ActivityThread.-wrap11(ActivityThread.java) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:148) at android.app.ActivityThread.main(ActivityThread.java:5417) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) Caused by: java.lang.IllegalStateException: PickerManager.sortingType.comparator must not be null at droidninja.filepicker.fragments.DocPickerFragment.setData(DocPickerFragment.kt:82) at droidninja.filepicker.fragments.DocPickerFragment.initView(DocPickerFragment.kt:66) at droidninja.filepicker.fragments.DocPickerFragment.onViewCreated(DocPickerFragment.kt:61) at androidx.fragment.app.FragmentManagerImpl.moveToState(FragmentManager.java:1471) at androidx.fragment.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManager.java:1784) at androidx.fragment.app.FragmentManagerImpl.moveToState(FragmentManager.java:1852) at androidx.fragment.app.BackStackRecord.executeOps(BackStackRecord.java:802) at androidx.fragment.app.FragmentManagerImpl.executeOps(FragmentManager.java:2625) at androidx.fragment.app.FragmentManagerImpl.executeOpsTogether(FragmentManager.java:2411) at androidx.fragment.app.FragmentManagerImpl.removeRedundantOperationsAndExecute(FragmentManager.java:2366) at androidx.fragment.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:2273) at androidx.fragment.app.FragmentManagerImpl.dispatchStateChange(FragmentManager.java:3273) at androidx.fragment.app.FragmentManagerImpl.dispatchActivityCreated(FragmentManager.java:3229) at androidx.fragment.app.FragmentController.dispatchActivityCreated(FragmentController.java:201) at androidx.fragment.app.FragmentActivity.onStart(FragmentActivity.java:620) at androidx.appcompat.app.AppCompatActivity.onStart(AppCompatActivity.java:178) at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1237) at android.app.Activity.performStart(Activity.java:6253) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2379) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)  at android.app.ActivityThread.-wrap11(ActivityThread.java)  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)  at android.os.Handler.dispatchMessage(Handler.java:102)  at android.os.Looper.loop(Looper.java:148)  at android.app.ActivityThread.main(ActivityThread.java:5417)  at java.lang.reflect.Method.invoke(Native Method)  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 

malcohmx avatar Oct 22 '18 06:10 malcohmx

@DroidNinja I have migrated my project to androidx and updated dependency to 2.2.0

I had to change my code of file picker from: FilePickerBuilder.getInstance().setMaxCount(1) .setSelectedFiles(filePaths) .setActivityTheme(R.style.LibAppTheme) .pickPhoto(this);

to: FilePickerBuilder.Companion.getInstance().setMaxCount(1) .setSelectedFiles(filePaths) .setActivityTheme(R.style.LibAppTheme) .pickPhoto(this);

Now when i tested the app after setting max compileSdkVersion to 28 i get this error: java.lang.NoClassDefFoundError: Failed resolution of: Lkotlin/jvm/internal/Intrinsics; at droidninja.filepicker.FilePickerBuilder.setSelectedFiles(Unknown Source:2)

KhanStan99 avatar Oct 22 '18 06:10 KhanStan99

@DroidNinja I have migrated my project to androidx and updated dependency to 2.2.0

I had to change my code of file picker from: FilePickerBuilder.getInstance().setMaxCount(1) .setSelectedFiles(filePaths) .setActivityTheme(R.style.LibAppTheme) .pickPhoto(this);

to: FilePickerBuilder.Companion.getInstance().setMaxCount(1) .setSelectedFiles(filePaths) .setActivityTheme(R.style.LibAppTheme) .pickPhoto(this);

Now when i tested the app after setting max compileSdkVersion to 28 i get this error: java.lang.NoClassDefFoundError: Failed resolution of: Lkotlin/jvm/internal/Intrinsics; at droidninja.filepicker.FilePickerBuilder.setSelectedFiles(Unknown Source:2)

Add this to your app level build.gradle

implementation 'org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.2.41'

malcohmx avatar Oct 22 '18 07:10 malcohmx

@DroidNinja I have migrated my project to androidx and updated dependency to 2.2.0 I had to change my code of file picker from: FilePickerBuilder.getInstance().setMaxCount(1) .setSelectedFiles(filePaths) .setActivityTheme(R.style.LibAppTheme) .pickPhoto(this); to: FilePickerBuilder.Companion.getInstance().setMaxCount(1) .setSelectedFiles(filePaths) .setActivityTheme(R.style.LibAppTheme) .pickPhoto(this); Now when i tested the app after setting max compileSdkVersion to 28 i get this error: java.lang.NoClassDefFoundError: Failed resolution of: Lkotlin/jvm/internal/Intrinsics; at droidninja.filepicker.FilePickerBuilder.setSelectedFiles(Unknown Source:2)

Add this to your app level build.gradle

implementation 'org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.2.41'

Thanks, that error is gone. But here is the new error I'm getting while picking file:

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.scoratech.scoraxchange.devbuild/droidninja.filepicker.FilePickerActivity}: java.lang.IllegalStateException: PickerManager.sortingType.comparator must not be null at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2779) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2857)

KhanStan99 avatar Oct 22 '18 07:10 KhanStan99

But here is the new error I'm getting while picking file:

I also have this error

alexeymorozua avatar Oct 24 '18 08:10 alexeymorozua

But here is the new error I'm getting while picking file:

I also have this error

check my previous replies.

Here is the solution I've resolved the issue by adding .sortDocumentsBy(SortingTypes.name) to the builder method.

malcohmx avatar Oct 24 '18 12:10 malcohmx

I solved this by :- (1.) Adding following to App Level build.gradle ->

dependency{
 ...
 implementation 'com.droidninja:filepicker:2.2.0'
 implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.2.71"
...
}

configurations {
    cleanedAnnotations
    compile.exclude group: 'org.jetbrains' , module:'annotations'
}

(2) Changing ->

FilePickerBuilder.getInstance().setMaxCount(1)
                                .setSelectedFiles(file_paths)
                                .setActivityTheme(R.style.FilePickerTheme)
                                .pickPhoto(this);
             --- TO ---
FilePickerBuilder.Companion.getInstance().setMaxCount(1)
                                .setSelectedFiles(file_paths)
                                .setActivityTheme(R.style.FilePickerTheme)
                                .sortDocumentsBy(SortingTypes.name)
                                .pickPhoto(this);

dishantghai avatar Oct 25 '18 23:10 dishantghai

I solved this by :- (1.) Adding following to App Level build.gradle ->

dependency{
 ...
 implementation 'com.droidninja:filepicker:2.2.0'
 implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.2.71"
...
}

configurations {
    cleanedAnnotations
    compile.exclude group: 'org.jetbrains' , module:'annotations'
}

(2) Changing ->

FilePickerBuilder.getInstance().setMaxCount(1)
                                .setSelectedFiles(file_paths)
                                .setActivityTheme(R.style.FilePickerTheme)
                                .pickPhoto(this);
             --- TO ---
FilePickerBuilder.Companion.getInstance().setMaxCount(1)
                                .setSelectedFiles(file_paths)
                                .setActivityTheme(R.style.FilePickerTheme)
                                .sortDocumentsBy(SortingTypes.name)
                                .pickPhoto(this);

You moved your project your AndroidX?and tested both file and photo picker?

KhanStan99 avatar Oct 29 '18 06:10 KhanStan99

I tried @dishantghai changes.

Getting this error: error: cannot access Fragment class file for androidx.fragment.app.Fragment not found

KhanStan99 avatar Oct 29 '18 07:10 KhanStan99

I tried @dishantghai changes.

Getting this error: error: cannot access Fragment class file for androidx.fragment.app.Fragment not found

i have same error

mohammadidiab avatar Oct 29 '18 10:10 mohammadidiab

download last comment before converted to kotlin from this link : https://github.com/DroidNinja/Android-FilePicker/tree/95216ceeeac3ea95939f6fcf0d1d18ea320d4829 then you can update the compileSdkVersion 28 targetSdkVersion 26

then add implementation project(path: ':filepicker', configuration: 'default')

then go to DocScannerTask replace

private HashMap<FileType, List<Document>> createDocumentType(ArrayList<Document> documents) { HashMap<FileType, List<Document>> documentMap = new HashMap<>(); for (final FileType fileType : fileTypes) { Predicate<Document> docContainsTypeExtension = new Predicate<Document>() { public boolean apply(Document document) { return document.isThisType(fileType.extensions); } }; ArrayList<Document> documentListFilteredByType = (ArrayList<Document>) FilePickerUtils.filter(documents, docContainsTypeExtension); if (comparator != null) Collections.sort(documentListFilteredByType, comparator); documentMap.put(fileType, documentListFilteredByType); } return documentMap; }

To

private HashMap<FileType, List<Document>> createDocumentType(ArrayList<Document> documents) {HashMap<FileType, List<Document>> documentMap = new HashMap<>(); for (final FileType fileType : fileTypes) { ArrayList<Document> documentListFilteredByType = new ArrayList<>(); for (Document doc: documents) { if (doc.isThisType(fileType.extensions)) { documentListFilteredByType.add(doc); } } if (comparator != null) Collections.sort(documentListFilteredByType, comparator); documentMap.put(fileType, documentListFilteredByType); } return documentMap; }

then Go to FilePickerUtils And remove public static <T> Collection<T> filter(Collection<T> target, Predicate<T> predicate) { Collection<T> result = new ArrayList<T>(); for (T element : target) { if (predicate**.apply**(element)) { result.add(element); } } return result; }

@KhanStan99

mohammadidiab avatar Oct 29 '18 12:10 mohammadidiab

tried @dishantghai changes.

Getting this error: error: cannot access Fragment class file for androidx.fragment.app.Fragment not found

Any solution to this issue yet..?

him2016 avatar Oct 31 '18 10:10 him2016

@DroidNinja Please help us out. Can we use your library on latest SDK without migrating to androidx ?

KhanStan99 avatar Nov 08 '18 10:11 KhanStan99

I have the same issue.

LaoXiZi avatar Nov 20 '18 03:11 LaoXiZi

I tried @dishantghai changes.

Getting this error: error: cannot access Fragment class file for androidx.fragment.app.Fragment not found

Is anyone find solution for this issue?

KS-Balaji avatar Nov 23 '18 15:11 KS-Balaji

I can't find hope to fix the bug as soon as possible

LaoXiZi avatar Nov 26 '18 11:11 LaoXiZi

have this issue too

astend avatar Nov 26 '18 14:11 astend

Please help to fix this issues. :(

kantbinh avatar Nov 28 '18 02:11 kantbinh

I solved this by :- (1.) Adding following to App Level build.gradle ->

dependency{
 ...
 implementation 'com.droidninja:filepicker:2.2.0'
 implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.2.71"
...
}

configurations {
    cleanedAnnotations
    compile.exclude group: 'org.jetbrains' , module:'annotations'
}

(2) Changing ->

FilePickerBuilder.getInstance().setMaxCount(1)
                                .setSelectedFiles(file_paths)
                                .setActivityTheme(R.style.FilePickerTheme)
                                .pickPhoto(this);
             --- TO ---
FilePickerBuilder.Companion.getInstance().setMaxCount(1)
                                .setSelectedFiles(file_paths)
                                .setActivityTheme(R.style.FilePickerTheme)
                                .sortDocumentsBy(SortingTypes.name)
                                .pickPhoto(this);

You moved your project your AndroidX?and tested both file and photo picker?

Awesome. The .sortDocumentsBy(SortingTypes.name) works with androidX both file and photo picker

Henriquedn avatar Nov 30 '18 19:11 Henriquedn

Change compileSdkVersion to version 28 and then override method createDocumentType of DocScannerTask.java like this

private HashMap<FileType, List<Document>> createDocumentType(ArrayList<Document> documents) {
    HashMap<FileType, List<Document>> documentMap = new HashMap<>();

    for (final FileType fileType : fileTypes) {
      ArrayList<Document> documentListFilteredByType = new ArrayList<>();
      for (Document doc: documents) {
        if (doc.isThisType(fileType.extensions)) {
          documentListFilteredByType.add(doc);
        }
      }
      if (comparator != null) Collections.sort(documentListFilteredByType, comparator);
      documentMap.put(fileType, documentListFilteredByType);
    }

    return documentMap;
  }

How to do that with the gradle dependancy 2.2.0?

asdec avatar Feb 18 '19 12:02 asdec

download last comment before converted to kotlin from this link : https://github.com/DroidNinja/Android-FilePicker/tree/95216ceeeac3ea95939f6fcf0d1d18ea320d4829 then you can update the compileSdkVersion 28 targetSdkVersion 26

then add implementation project(path: ':filepicker', configuration: 'default')

then go to DocScannerTask replace

private HashMap<FileType, List<Document>> createDocumentType(ArrayList<Document> documents) { HashMap<FileType, List<Document>> documentMap = new HashMap<>(); for (final FileType fileType : fileTypes) { Predicate<Document> docContainsTypeExtension = new Predicate<Document>() { public boolean apply(Document document) { return document.isThisType(fileType.extensions); } }; ArrayList<Document> documentListFilteredByType = (ArrayList<Document>) FilePickerUtils.filter(documents, docContainsTypeExtension); if (comparator != null) Collections.sort(documentListFilteredByType, comparator); documentMap.put(fileType, documentListFilteredByType); } return documentMap; }

To

private HashMap<FileType, List<Document>> createDocumentType(ArrayList<Document> documents) {HashMap<FileType, List<Document>> documentMap = new HashMap<>(); for (final FileType fileType : fileTypes) { ArrayList<Document> documentListFilteredByType = new ArrayList<>(); for (Document doc: documents) { if (doc.isThisType(fileType.extensions)) { documentListFilteredByType.add(doc); } } if (comparator != null) Collections.sort(documentListFilteredByType, comparator); documentMap.put(fileType, documentListFilteredByType); } return documentMap; }

then Go to FilePickerUtils And remove public static <T> Collection<T> filter(Collection<T> target, Predicate<T> predicate) { Collection<T> result = new ArrayList<T>(); for (T element : target) { if (predicate**.apply**(element)) { result.add(element); } } return result; }

@KhanStan99

fix this isuue

    compileSdkVersion 28
    buildToolsVersion '28.0.3'

    defaultConfig {
        minSdkVersion 17
        targetSdkVersion 28
        versionCode 1
        versionName version
    }

    implementation 'com.github.bumptech.glide:glide:4.8.0'

filepicker-2.1.5-20190416-aar.zip

zero-li avatar Apr 16 '19 02:04 zero-li