ImagePicker icon indicating copy to clipboard operation
ImagePicker copied to clipboard

Photo picker does not open with compile sdk 33 (Android 13)

Open fairEnough83 opened this issue 3 years ago • 5 comments

Describe the bug App picker does not open with compile sdk 33 after permission handling Tested with version 32 (Android 12) and it works

Sample code:

` val launcher = rememberLauncherForActivityResult(ActivityResultContracts.StartActivityForResult()) { if (it.resultCode == Activity.RESULT_OK) { onAvatarChanged(it.data?.data!!) } }

    AvatarImageUI(
        initials = firstName?.take(2) ?: "",
        avatarUri = avatarUrl,
        fontSize = 50.sp,
        canEdit = canEditAvatar,
        onEditClick = {
            ImagePicker.with(activity)
                .maxResultSize(maxAvatarSize, maxAvatarSize)
                .cropSquare()
                .provider(ImageProvider.BOTH)
                .setOutputFormat(
                    if (Utils.isAtleastR()) Bitmap.CompressFormat.WEBP_LOSSY else Bitmap.CompressFormat.WEBP
                )
                .createIntentFromDialog { launcher.launch(it) }
        },
        size = Constants.Size.AVATAR_BIG,
    )`

Looking forward to you comments. Thank you in advance

fairEnough83 avatar Sep 09 '22 07:09 fairEnough83

I tested and it worked just fine; Even without changing the compileSdkVersion and targetsdkVersion of the library to 32.

Please try the sample app of this repo, and let me know if you have any issue on 32 or not

Drjacky avatar Sep 09 '22 08:09 Drjacky

@Drjacky just one update - it did also work well with compile sdk 33 on an non android 13 device - but when switching to android 13 device it's not.

which device did you use for testing - Android 13? Thank in advance

fairEnough83 avatar Sep 09 '22 09:09 fairEnough83

Yes, Pixel 4, Android 13

Drjacky avatar Sep 09 '22 09:09 Drjacky

last question: Did you use the sample inside this project to verfiy - If yes, I'll test this code on my devices?

fairEnough83 avatar Sep 09 '22 09:09 fairEnough83

Yes. please try the sample and let me know if it works or not.

Drjacky avatar Sep 09 '22 09:09 Drjacky

@Drjacky @fairEnough83 is right, this requires a change for Android 13: https://developer.android.com/about/versions/13/behavior-changes-13#granular-media-permissions

Seems like simply using Manifest.permission.READ_MEDIA_IMAGES for API level >= 33 inside GalleryProvider.REQUIRED_PERMISSIONS does the trick!

astuetz avatar Sep 19 '22 20:09 astuetz

It's fixed on 2.3.19. Please test it and let me know if it didn't work.

Drjacky avatar Sep 20 '22 14:09 Drjacky

Tried it on the sample app and it works fine, UNTIL I switch the dependency from the local module to the latest maven artifact:

// implementation project(':imagepicker')
implementation "com.github.Drjacky:ImagePicker:2.3.19"

By doing so, the sample app again tells me that the storage permission is required.

If I look at the downloaded apk sources (or try to look at GalleryProvider inside AS), I can see the latest changes including READ_MEDIA_IMAGES. But as soon as I decompile the actual aar, all the latest changes are missing.

Looking at the report on jitpack, it also says ERROR: No build artifacts found at the very end, so maybe something's wrong with publishing?

Just to be safe I also tried clearing all my caches, but the problem still persists.

astuetz avatar Sep 20 '22 16:09 astuetz

@Drjacky do you have any updates on this or is there any way I could help? In the meantime, maybe you can re-open the issue, since it's not actually fixed Thanks!

astuetz avatar Sep 26 '22 11:09 astuetz

Thanks @astuetz! sure, the help would be to find the root of issue you've mentioned here I don't have much time this week to look at it, any help is appreciated.

Drjacky avatar Sep 26 '22 11:09 Drjacky

@Drjacky I opened a PR here, which bumps AGP and Gradle versions and also fixes ktlint errors. Running ./gradlew :imagepicker:build now works fine for me. Would be great if you'd have some time to try it yourself and see if publishing works properly. Thanks!

astuetz avatar Sep 28 '22 09:09 astuetz

@astuetz Could you let me know what are the versions?

  • Android Studio
  • echo $JAVA_HOME
  • Preferences -> Build -> Gradle -> JDK

I still get this: gradle build

Execution failed for task ':imagepicker:ktlint'. Process 'command '/Library/Java/JavaVirtualMachines/jdk-11.0.9.jdk/Contents/Home/bin/java'' finished with non-zero exit value 1

Drjacky avatar Sep 28 '22 18:09 Drjacky

@astuetz Also, could you try this 2.3.20? But not from jitpack. from maven. Cause now I get a new error in jitpack log now: https://jitpack.io/com/github/Drjacky/ImagePicker/2.3.20/build.log

Drjacky avatar Sep 28 '22 20:09 Drjacky

Hey, I can confirm that 2.3.20 works fine now! I guess my PR is no longer needed then?

astuetz avatar Sep 28 '22 20:09 astuetz

Fixed on 2.3.20.

Drjacky avatar Sep 29 '22 07:09 Drjacky