alphamu / PinEntryEditText

An EditText that looks like a pin entry field. It is highly customisable and even animated text.
Apache License 2.0
670 stars 137 forks source link

Crash with AndroidX 1.0.0 #45

Closed gmk57 closed 5 years ago

gmk57 commented 5 years ago

Hello & thanks for your work! Latest versions (2.0.0-RC1 & 2.0.1-RC1), used with AndroidX 1.0.0, crash in runtime with: java.lang.NoClassDefFoundError: Failed resolution of: Landroidx/legacy/view/ViewCompat; This class is marked as deprecated and seems to be removed from AndroidX artifacts. Probably replacing androidx.legacy.view.ViewCompat with androidx.core.view.ViewCompat will resolve this issue.

gmk57 commented 5 years ago

Version 2.0.1 still crashes.

KaiserY commented 5 years ago

One workaround is explicitly adding legacy support dependency: implementation 'androidx.legacy:legacy-support-v13:1.0.0'

alphamu commented 5 years ago

The app bundled with the library's source works. So, what are you doing differently? Or rather, are you suggesting that I use androidx.core.view.ViewCompat instead of the legacy one?

alphamu commented 5 years ago

If you're following the include instructions and excluding the legacy library. Then you have to make sure to import it in your app. The main reason to exclude the library when importing it into your project is to avoid version conflicts that can occur some times when the library uses a newer version of the included library than you do. But, you need to make sure that if you exclude those androidx libraries, that you include them in your code. I'll do an other release soon where I switch to the androidx.core.view.ViewCompat and hopefully reduce one import.

gmk57 commented 5 years ago

I had appcompat dependency, but not support-v13 (never used it, honestly). Also tried without excluding these artifacts, but it didn't help, since your library does not seem to have any transitive dependencies (see screenshot). Switching to androidx.core.view.ViewCompat would be very nice, because androidx.core:core is already pulled by appcompat. screenshot

alphamu commented 5 years ago

Replaceing legacy.ViewCompat and core.ViewCompat doesn't seem to be working: Checkout the branch remove-viewcompat I still get an error that it can't find legacy ViewCompat. any ideas?


2018-10-10 16:03:20.749 8553-8553/? E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.alimuzaffar.sample.pin, PID: 8553
    java.lang.NoClassDefFoundError: Failed resolution of: Landroidx/legacy/view/ViewCompat;
        at com.alimuzaffar.lib.pin.PinEntryEditText.onSizeChanged(PinEntryEditText.java:262)
        at android.view.View.sizeChange(View.java:17626)
        at android.view.View.setFrame(View.java:17588)
        at android.widget.TextView.setFrame(TextView.java:5098)
        at android.view.View.layout(View.java:17505)
        at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1737)
        at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1581)
        at android.widget.LinearLayout.onLayout(LinearLayout.java:1490)
        at android.view.View.layout(View.java:17508)
        at android.view.ViewGroup.layout(ViewGroup.java:5555)
        at android.widget.FrameLayout.layoutChildren(FrameLayout.java:323)
        at android.widget.FrameLayout.onLayout(FrameLayout.java:261)
        at android.widget.ScrollView.onLayout(ScrollView.java:1535)
        at android.view.View.layout(View.java:17508)
        at android.view.ViewGroup.layout(ViewGroup.java:5555)
        at android.widget.FrameLayout.layoutChildren(FrameLayout.java:323)
        at android.widget.FrameLayout.onLayout(FrameLayout.java:261)
        at android.view.View.layout(View.java:17508)
        at android.view.ViewGroup.layout(ViewGroup.java:5555)
        at androidx.appcompat.widget.ActionBarOverlayLayout.onLayout(ActionBarOverlayLayout.java:444)
        at android.view.View.layout(View.java:17508)
        at android.view.ViewGroup.layout(ViewGroup.java:5555)
        at android.widget.FrameLayout.layoutChildren(FrameLayout.java:323)
        at android.widget.FrameLayout.onLayout(FrameLayout.java:261)
        at android.view.View.layout(View.java:17508)
        at android.view.ViewGroup.layout(ViewGroup.java:5555)
        at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1737)
        at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1581)
        at android.widget.LinearLayout.onLayout(LinearLayout.java:1490)
        at android.view.View.layout(View.java:17508)
        at android.view.ViewGroup.layout(ViewGroup.java:5555)
        at android.widget.FrameLayout.layoutChildren(FrameLayout.java:323)
        at android.widget.FrameLayout.onLayout(FrameLayout.java:261)
        at com.android.internal.policy.DecorView.onLayout(DecorView.java:701)
        at android.view.View.layout(View.java:17508)
        at android.view.ViewGroup.layout(ViewGroup.java:5555)
        at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:2319)
        at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2049)
        at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1240)
        at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6298)
        at android.view.Choreographer$CallbackRecord.run(Choreographer.java:858)
        at android.view.Choreographer.doCallbacks(Choreographer.java:670)
        at android.view.Choreographer.doFrame(Choreographer.java:606)
        at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:844)
        at android.os.Handler.handleCallback(Handler.java:751)
        at android.os.Handler.dispatchMessage(Handler.java:95)
        at android.os.Looper.loop(Looper.java:154)
        at android.app.ActivityThread.main(ActivityThread.java:5969)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:801)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:691)
2018-10-10 16:03:20.749 8553-8553/? E/AndroidRuntime: Caused by: java.lang.ClassNotFoundException: Didn't find class "androidx.legacy.view.ViewCompat" on path: DexPathList[[zip file "/data/app/com.alimuzaffar.sample.pin-2/base.apk", zip file "/data/app/com.alimuzaffar.sample.pin-2/split_lib_dependencies_apk.apk", zip file "/data/app/com.alimuzaffar.sample.pin-2/split_lib_slice_0_apk.apk", zip file "/data/app/com.alimuzaffar.sample.pin-2/split_lib_slice_1_apk.apk", zip file "/data/app/com.alimuzaffar.sample.pin-2/split_lib_slice_2_apk.apk", zip file "/data/app/com.alimuzaffar.sample.pin-2/split_lib_slice_3_apk.apk", zip file "/data/app/com.alimuzaffar.sample.pin-2/split_lib_slice_4_apk.apk", zip file "/data/app/com.alimuzaffar.sample.pin-2/split_lib_slice_5_apk.apk", zip file "/data/app/com.alimuzaffar.sample.pin-2/split_lib_slice_6_apk.apk", zip file "/data/app/com.alimuzaffar.sample.pin-2/split_lib_slice_7_apk.apk", zip file "/data/app/com.alimuzaffar.sample.pin-2/split_lib_slice_8_apk.apk", zip file "/data/app/com.alimuzaffar.sample.pin-2/split_lib_slice_9_apk.apk"],nativeLibraryDirectories=[/data/app/com.alimuzaffar.sample.pin-2/lib/x86, /system/lib, /vendor/lib]]
        at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:380)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
            ... 51 more```
gmk57 commented 5 years ago

It seems that the crash is caused by using old published version of library in your sample project's build.gradle: implementation ('com.alimuzaffar.lib:pinentryedittext:2.0.1') After reverting to implementation project(':pinentryedittext') it works fine for me. :)

alphamu commented 5 years ago

AAAAAAAAAArg! I've released 2.0.2 to bintray. Please give it a try and let me know if this solves your problem.

gmk57 commented 5 years ago

It works, thank you very much! :))

What do you intend to do with appcompat dependency? It seems that current artifact does not pull any transitive dependencies (see my screenshot above, this is still the case for 2.0.2).

I'm not an expert in libs publishing, but POM files for recent releases do not contain <dependencies> block. Last version that contained it was 1.3.1.

There are probably two choices:

    • Leave the code as is
    • Simplify examples in README to something like implementation 'com.alimuzaffar.lib:pinentryedittext:2.0.2' (as there is nothing to exclude)
    • Separately mention that project must define appcompat dependency itself.
    • Dig out why dependencies get lost (publishing plugin bug?)
    • Consider simplifying examples in README to something like implementation 'com.alimuzaffar.lib:pinentryedittext:2.0.2' I'm not sure if excluding dependencies makes much sense. It's better to notice compatibility problems at compile time than at runtime, and with new semantic versioning there should be less false version conflicts.
alphamu commented 5 years ago

I suspect this might be because of a change to the manifest.

Because of a different issue, I had to remove the application block from the manifest. Apparently having a label etc there in the application block conflicts in some apps and that libraries aren't supposed to have this. I'll double check don't popular libraries and see how they handle this.

I'll test different variations after removing appcompat from the sample application to see how this works.

I'll get back to you if I find something. If you manage to fix it, please make a pull request.

On Wed., 10 Oct. 2018, 11:07 am gmk57, notifications@github.com wrote:

It works, thank you very much! :))

What do you intend to do with appcompat dependency? It seems that current artifact does not pull any transitive dependencies (see my screenshot above, this is still the case for 2.0.2).

I'm not an expert in libs publishing, but POM files for recent releases do not contain https://dl.bintray.com/alphamu/customwidgets/com/alimuzaffar/lib/pinentryedittext/2.0.2/pinentryedittext-2.0.2.pom

block. Last version that contained it was 1.3.1 . There are probably two choices: 1. - Leave the code as is - Simplify examples in README to something like implementation 'com.alimuzaffar.lib:pinentryedittext:2.0.2' (as there is nothing to exclude) - Separately mention that project must define appcompat dependency itself. 2. - Dig out why dependencies get lost (publishing plugin bug?) - Consider simplifying examples in README to something like implementation 'com.alimuzaffar.lib:pinentryedittext:2.0.2' I'm not sure if excluding dependencies makes much sense. It's better to notice compatibility problems at compile time than at runtime, and with new semantic versioning there should be less false version conflicts. — You are receiving this because you commented. Reply to this email directly, view it on GitHub , or mute the thread .
gmk57 commented 5 years ago

Version 1.3.3 released Feb 25, 2018 already did not have dependencies declared. This may be related to implementation Gradle scope and this issue in android-maven-gradle-plugin

alphamu commented 5 years ago

My tests showed that if I used api instead of implementation the dependencies become transitive... I could have read the documentation to learn the same thing :-P. I've published a newer version of both widgets and the dependency should be transitive. I've chosen to make the dependency transitive instead of asking the users to include appcompat because the widget will simply not work without this dependency so it should be transitive. The exclude then gives the user to option to use a newer version if they want.

gmk57 commented 5 years ago

I still do not see transitive dependencies for 2.0.3 (neither in POM nor in Gradle dependencies report). :( If this issue is to blame, you may need to update android-maven-gradle-plugin.

alphamu commented 5 years ago

I'll take a look, but I don't create a POM. I'm not sure what is happening, but the behaviour seems correct in the sample app. clearly someone is happening when the library is bundled and uploaded. I've synced it to maven, let me know if that made any difference, otherwise I'll investigate this again.

On Wed., 10 Oct. 2018, 2:14 pm gmk57, notifications@github.com wrote:

I still do not see transitive dependencies for 2.0.3 (neither in POM nor in Gradle dependencies report). :( If this issue https://github.com/dcendents/android-maven-gradle-plugin/issues/61 is to blame, you may need to update android-maven-gradle-plugin.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/alphamu/PinEntryEditText/issues/45#issuecomment-428548684, or mute the thread https://github.com/notifications/unsubscribe-auth/AAzkjL8OiHTB6qtfGgwRTrBDyvCXc3Kkks5ujeSzgaJpZM4W4TrR .

gmk57 commented 5 years ago

Sample app is in the same project with the library, so it may behave differently.

AFAIK, POM files are generated by android-maven-gradle-plugin (see classpath 'com.github.dcendents:android-maven-gradle-plugin:1.4.1' in your top-level build.gradle) and published on Bintray (here's the latest). They contain library metadata, including its transitive dependencies. There was indeed <dependencies> section in version 1.3.1 (and earlier).

To verify you can:

  1. Look at the published POM file, or
  2. Create a new empty project, add implementation 'com.alimuzaffar.lib:pinentryedittext:2.0.3' to your app\build.gradle and run Gradle (in the top right corner) -> Project name -> :app -> Tasks -> help -> dependencies. You will see dependency tree.
alphamu commented 5 years ago

Updating the publishing plugins seems to have solved the issue. I was basically using the wrong version of the android-maven-gradle-plugin for my version of gradle.

gmk57 commented 5 years ago

Glad to hear it! In v.2.0.4 there is indeed a transitive appcompat dependency. Thanks!