garretyoder / Colorful

Android runtime theme library
Apache License 2.0
2.13k stars 193 forks source link

Use THEME_MATERIAL appear error log #35

Closed tcqq closed 6 years ago

tcqq commented 6 years ago

@garretyoder If use THEME_MATERIAL or THEME_MATERIAL_COMPONETS, the following error will appear. What did i do wrong?

Code ColorfulKt.Colorful().apply(this, true, BaseTheme.THEME_MATERIAL_COMPONETS);

    <style name="AppTheme" parent="Theme.MaterialComponents.Light.NoActionBar">
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
    </style>

Log

AppCompatDelegate: Failed to instantiate custom view inflater android.support.design.theme.MaterialComponentsViewInflater . Falling back to default.
    java.lang.ClassNotFoundException: Invalid name: android.support.design.theme.MaterialComponentsViewInflater 
        at java.lang.Class.classForName(Native Method)
        at java.lang.Class.forName(Class.java:453)
        at java.lang.Class.forName(Class.java:378)
        at android.support.v7.app.AppCompatDelegateImplV9.createView(AppCompatDelegateImplV9.java:1014)
        at android.support.v7.app.AppCompatDelegateImplV9.onCreateView(AppCompatDelegateImplV9.java:1092)
garretyoder commented 6 years ago

If you're inheriting your base style from Theme.MaterialComponets to use the new MaterialComponets theme, you need to add the new design library as a dependency to your project.

https://github.com/material-components/material-components-android/blob/master/docs/getting-started.md

tcqq commented 6 years ago

But I am using this version now: com.android.support:design:28.0.0-alpha1, because "28.0.0-alpha1" version contains "material-components"

garretyoder commented 6 years ago

The material componets theme is still very much alpha as far as Google is concerned, hence the -alpha denotation. I recommend matching the version you're using to the version Colorful is using.

implementation 'com.google.android.material:material:1.0.0-alpha1'

the sdk28 version is depending on P. I don't plan on moving Colorful's SDK to android P until P's apis are marked stable in DP3.

tcqq commented 6 years ago

Hi, I tested it, when I change the support library version from 28.0.0-alpha1 to 27.1.1 and add the com.google.android.material:material:1.0.0-alpha1 library, I get an error

image

The error is fixed when I change the support library version from 27.1.1 to 28-alpha1 and delete the com.google.android.material:material:1.0.0-alpha1 library

image

tcqq commented 6 years ago

When I remove exclude group: 'com.google.android.material', module: 'material', the above error will appear again.

    api (com.github.garretyoder:Colorful:2.3.2) {
        exclude group: 'com.google.android.material', module: 'material'
    }

If do not delete, the above error will not appear, but the log will have the following error.

AppCompatDelegate: Failed to instantiate custom view inflater android.support.design.theme.MaterialComponentsViewInflater . Falling back to default.
    java.lang.ClassNotFoundException: Invalid name: android.support.design.theme.MaterialComponentsViewInflater 
        at java.lang.Class.classForName(Native Method)
        at java.lang.Class.forName(Class.java:453)
        at java.lang.Class.forName(Class.java:378)
        at android.support.v7.app.AppCompatDelegateImplV9.createView(AppCompatDelegateImplV9.java:1014)
        at android.support.v7.app.AppCompatDelegateImplV9.onCreateView(AppCompatDelegateImplV9.java:1092)
tcqq commented 6 years ago

@garretyoder com.android.support and com.google.android.material cannot add at the same time. image I created a new project and tried to add it at the same time, occurred an error. image

tcqq commented 6 years ago

If I remove material library, and change support library version to 28.0.0-alpha1, now can run, but the log shows the following error image image

So fixing the following error I found two solutions:

  1. Support library use 28.0.0-alpha1 version , and use BaseTheme.THEME_APPCOMPAT instead of BaseTheme.THEME_MATERIAL or BaseTheme.THEME_MATERIAL_COMPONETS
  2. Refactoring to AndroidX, and use BaseTheme.THEME_APPCOMPAT or BaseTheme.THEME_MATERIAL or BaseTheme.THEME_MATERIAL_COMPONETS

Error log

AppCompatDelegate: Failed to instantiate custom view inflater android.support.design.theme.MaterialComponentsViewInflater . Falling back to default.
    java.lang.ClassNotFoundException: Invalid name: android.support.design.theme.MaterialComponentsViewInflater 
        at java.lang.Class.classForName(Native Method)
        at java.lang.Class.forName(Class.java:453)
        at java.lang.Class.forName(Class.java:378)
        at android.support.v7.app.AppCompatDelegateImplV9.createView(AppCompatDelegateImplV9.java:1014)
        at android.support.v7.app.AppCompatDelegateImplV9.onCreateView(AppCompatDelegateImplV9.java:1092)
garretyoder commented 6 years ago

Refactoring to AndroidX will fix the issue. I might make another release later today to try to enable some build magic to support the material components theme without relying on the new design library until it's marked stable.

garretyoder commented 6 years ago

I have rolled back support for the material componets theme in the stable branch as it's bound to androidx and android P, and will cause build errors when not targeting android P. If you wish to use the material componets theme, I've moved it into a new branch called 'android-p' where you can build it.

tcqq commented 6 years ago

Ok.