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

No static method MonetCompatDynamicTheme With Jetpack Compose #11

Open
owenlejeune opened this issue Mar 18, 2022 · 12 comments
Open

No static method MonetCompatDynamicTheme With Jetpack Compose #11

owenlejeune opened this issue Mar 18, 2022 · 12 comments

Comments

@owenlejeune
Copy link

I followed the setup guide (enable PaletteCompat in Application, implement custom MonetCompatActivity based on ComponentActivity, using MonetCompatDynamicTheme) but I'm getting this error when trying to run my application

java.lang.NoSuchMethodError: No static method MonetCompatDynamicTheme(Lcom/kieronquinn/monetcompat/core/MonetCompat;Lkotlin/jvm/functions/Function2;Landroidx/compose/runtime/Composer;I)V in class Lcom/kieronquinn/monetcompat/compose/MonetCompatThemeKt; or its super classes (declaration of 'com.kieronquinn.monetcompat.compose.MonetCompatThemeKt' appears in /data/app/~~W4-GVauu1KbA2jmEvOaszg==/com.owenlejeune.tvtime-GXupWNu-YmGy4Ey1Pr3eLw==/base.apk!classes13.dex)

I tried enabling Multidex but that didn't solve the issue either.

@KieronQuinn
Copy link
Owner

The Compose implementation was done by @rozPierog, maybe they can help with this? I don't have much Compose knowledge unfortunately.

@huaweikai
Copy link

只需要将MonetCompatDynamicTheme.kt提取出来,就可以了。
然后我们只需要将我们的activity继承MonetCompatActivity即可。
You just need to extract the MonetCompatDynamicTheme.kt

Then we just need to inherit our activity from MonetCompatActivity.

@rozPierog
Copy link
Contributor

Your activity should inherit from MonetCompatActivity.kt, sorry about not including it in any docs

@owenlejeune
Copy link
Author

@rozPierog Thanks for the clarification. I changed my main activity to extend MonetCompatActivity instead of implementing it myself but I'm still getting the same error

@rozPierog
Copy link
Contributor

Can you send me your code? I could look into this. If not please refer to https://github.com/rozPierog/Cofi code to look at how I did it @owenlejeune

@huaweikai
Copy link

Is error a theme error?

@owenlejeune
Copy link
Author

@rozPierog Here is the code I'm using

class MainActivity : MonetCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        setTheme(R.style.Theme_TVTime)
        super.onCreate(savedInstanceState)

        CoroutineScope(Dispatchers.IO).launch {
            SessionManager.initialize()
        }

        lifecycleScope.launchWhenCreated {
            monet.awaitMonetReady()
        }

        setContent(null) {
            MyApp(
                monet = monet,
                appNavController = rememberNavController()
            )
        }
    }
}

@Composable
fun MyApp(
    monet: MonetCompat,
    appNavController: NavHostController = rememberNavController()
) {
    MonetCompatDynamicTheme(
        monet = monet
    ) {
        Box {
            MainNavigationRoutes(navController = appNavController)
        }
    }
}

@huaweikai
Copy link

@owenlejeune hey boy.If you still get No static method MonetCompatDynamicTheme With Jetpack Compose, I recommend you write one for the component function in the dependency library, like this.

class TestActivity : MonetCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        lifecycleScope.launchWhenCreated {
            monet.awaitMonetReady()
            setContent {
                MonetTheme(monet = monet) {
                    Box(
                        modifier = Modifier
                            .fillMaxSize()
                            .background(MaterialTheme.colorScheme.primary),
                        contentAlignment = Alignment.Center
                    ){
                        Text(text = "shenmemeeeee")
                    }
                }
            }
        }
    }
}

@Composable
fun MonetTheme(
    monet: MonetCompat,
    content: @Composable () -> Unit
) {
    MaterialTheme(
        colorScheme = if (isSystemInDarkTheme()) {
            monet.darkMonetCompatScheme()
        } else {
            monet.lightMonetCompatScheme()
        }, content = content
    )
}

But I have to warn you, if you report an error like this

You need to use a Theme.AppCompat theme (or descendant) with this activity.

This is because the open source library inherits appcompatActivities and can't use a material Theme, instead using Theme.AppCompat. This is when you change the theme for the activity in your Sse instructions, like this

        <activity android:name=".TestActivity"
            android:exported="true"
            android:theme="@style/Theme.AppCompat.NoActionBar">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

@owenlejeune
Copy link
Author

@huaweikai Thanks for the suggestion! I tried MonetCompatDynamicTheme with MaterialTheme and passing in the monet color scheme but I'm not getting a different error

E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.owenlejeune.tvtime, PID: 7060
    java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/android/material/color/DynamicColors;
        at com.kieronquinn.monetcompat.core.MonetCompat$Companion.getUseSystemColors(MonetCompat.kt:90)
        at com.kieronquinn.monetcompat.core.MonetCompat$Companion.access$getUseSystemColors(MonetCompat.kt:39)
        at com.kieronquinn.monetcompat.core.MonetCompat.registerWallpaperColorsChangedReceiver(MonetCompat.kt:509)
        at com.kieronquinn.monetcompat.core.MonetCompat.access$registerWallpaperColorsChangedReceiver(MonetCompat.kt:37)
        at com.kieronquinn.monetcompat.core.MonetCompat$Companion.setup(MonetCompat.kt:138)
        at com.kieronquinn.monetcompat.app.MonetCompatActivity.onCreate(MonetCompatActivity.kt:57)
        at com.owenlejeune.tvtime.MainActivity.onCreate(MainActivity.kt:33)
        at android.app.Activity.performCreate(Activity.java:8051)
        at android.app.Activity.performCreate(Activity.java:8031)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1329)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3608)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3792)
        at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:103)
        at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2210)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loopOnce(Looper.java:201)
        at android.os.Looper.loop(Looper.java:288)
        at android.app.ActivityThread.main(ActivityThread.java:7839)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003)
     Caused by: java.lang.ClassNotFoundException: Didn't find class "com.google.android.material.color.DynamicColors" on path: DexPathList[[dex file "/data/data/com.owenlejeune.tvtime/code_cache/.overlay/base.apk/classes3.dex", zip file "/data/app/~~d0ieWpSLKfORSlttaBsEew==/com.owenlejeune.tvtime-Nmkp6pQnqWfIyhJZb65nJQ==/base.apk"],nativeLibraryDirectories=[/data/app/~~d0ieWpSLKfORSlttaBsEew==/com.owenlejeune.tvtime-Nmkp6pQnqWfIyhJZb65nJQ==/lib/x86_64, /system/lib64, /system_ext/lib64]]
        at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:218)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
        at com.kieronquinn.monetcompat.core.MonetCompat$Companion.getUseSystemColors(MonetCompat.kt:90) 
        at com.kieronquinn.monetcompat.core.MonetCompat$Companion.access$getUseSystemColors(MonetCompat.kt:39) 
        at com.kieronquinn.monetcompat.core.MonetCompat.registerWallpaperColorsChangedReceiver(MonetCompat.kt:509) 
        at com.kieronquinn.monetcompat.core.MonetCompat.access$registerWallpaperColorsChangedReceiver(MonetCompat.kt:37) 
        at com.kieronquinn.monetcompat.core.MonetCompat$Companion.setup(MonetCompat.kt:138) 
        at com.kieronquinn.monetcompat.app.MonetCompatActivity.onCreate(MonetCompatActivity.kt:57) 
        at com.owenlejeune.tvtime.MainActivity.onCreate(MainActivity.kt:33) 
        at android.app.Activity.performCreate(Activity.java:8051) 
        at android.app.Activity.performCreate(Activity.java:8031) 
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1329) 
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3608) 
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3792) 
        at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:103) 
        at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135) 
        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2210) 
        at android.os.Handler.dispatchMessage(Handler.java:106) 
        at android.os.Looper.loopOnce(Looper.java:201) 
        at android.os.Looper.loop(Looper.java:288) 
        at android.app.ActivityThread.main(ActivityThread.java:7839) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003) 

@huaweikai
Copy link

@owenlejeune I guess your Material version is the default for Android Studio
com.google.android.material:material
Because the author is based on material1.5.0-RC01
You can try upgrading the Material version to 1.5.0-RC01

@owenlejeune
Copy link
Author

@huaweikai this is so bizarre, added implementation "com.google.android.material:material:1.5.0-rc01" to my build.gradle and getting ANOTHER new error now

E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.owenlejeune.tvtime, PID: 15077
    java.lang.NoSuchMethodError: No static method darkMonetCompatScheme-QgNmWro(Lcom/kieronquinn/monetcompat/core/MonetCompat;JJJJJJJJJJJJJJJJJJJJJJLandroidx/compose/runtime/Composer;IIII)Landroidx/compose/material3/ColorScheme; in class Lcom/kieronquinn/monetcompat/compose/MonetCompatThemeKt; or its super classes (declaration of 'com.kieronquinn.monetcompat.compose.MonetCompatThemeKt' appears in /data/app/~~UblctgaDus8mnG96I4gtzQ==/com.owenlejeune.tvtime-Sfv2IjlpIyVtciqX7xeRSA==/base.apk!classes13.dex)
        at com.owenlejeune.tvtime.MainActivity.MyApp(MainActivity.kt:73)
        at com.owenlejeune.tvtime.MainActivity$onCreate$3.invoke(MainActivity.kt:55)
        at com.owenlejeune.tvtime.MainActivity$onCreate$3.invoke(MainActivity.kt:43)
        at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:107)
        at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:34)
        at androidx.compose.ui.platform.ComposeView.Content(ComposeView.android.kt:410)
        at androidx.compose.ui.platform.AbstractComposeView$ensureCompositionCreated$1.invoke(ComposeView.android.kt:252)
        at androidx.compose.ui.platform.AbstractComposeView$ensureCompositionCreated$1.invoke(ComposeView.android.kt:251)
        at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:107)
        at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:34)
        at androidx.compose.runtime.CompositionLocalKt.CompositionLocalProvider(CompositionLocal.kt:228)
        at androidx.compose.ui.platform.CompositionLocalsKt.ProvideCommonCompositionLocals(CompositionLocals.kt:166)
        at androidx.compose.ui.platform.AndroidCompositionLocals_androidKt$ProvideAndroidCompositionLocals$3.invoke(AndroidCompositionLocals.android.kt:123)
        at androidx.compose.ui.platform.AndroidCompositionLocals_androidKt$ProvideAndroidCompositionLocals$3.invoke(AndroidCompositionLocals.android.kt:122)
        at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:107)
        at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:34)
        at androidx.compose.runtime.CompositionLocalKt.CompositionLocalProvider(CompositionLocal.kt:228)
        at androidx.compose.ui.platform.AndroidCompositionLocals_androidKt.ProvideAndroidCompositionLocals(AndroidCompositionLocals.android.kt:114)
        at androidx.compose.ui.platform.WrappedComposition$setContent$1$1$3.invoke(Wrapper.android.kt:157)
        at androidx.compose.ui.platform.WrappedComposition$setContent$1$1$3.invoke(Wrapper.android.kt:156)
        at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:107)
        at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:34)
        at androidx.compose.runtime.CompositionLocalKt.CompositionLocalProvider(CompositionLocal.kt:228)
        at androidx.compose.ui.platform.WrappedComposition$setContent$1$1.invoke(Wrapper.android.kt:156)
        at androidx.compose.ui.platform.WrappedComposition$setContent$1$1.invoke(Wrapper.android.kt:140)
        at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:107)
        at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:34)
        at androidx.compose.runtime.ComposerKt.invokeComposable(Composer.kt:3337)
        at androidx.compose.runtime.ComposerImpl$doCompose$2$5.invoke(Composer.kt:2582)
        at androidx.compose.runtime.ComposerImpl$doCompose$2$5.invoke(Composer.kt:2571)
        at androidx.compose.runtime.SnapshotStateKt__DerivedStateKt.observeDerivedStateRecalculations(DerivedState.kt:247)
        at androidx.compose.runtime.SnapshotStateKt.observeDerivedStateRecalculations(Unknown Source:1)
        at androidx.compose.runtime.ComposerImpl.doCompose(Composer.kt:2571)
        at androidx.compose.runtime.ComposerImpl.composeContent$runtime_release(Composer.kt:2522)
        at androidx.compose.runtime.CompositionImpl.composeContent(Composition.kt:478)
E/AndroidRuntime:     at androidx.compose.runtime.Recomposer.composeInitial$runtime_release(Recomposer.kt:748)
        at androidx.compose.runtime.CompositionImpl.setContent(Composition.kt:433)
        at androidx.compose.ui.platform.WrappedComposition$setContent$1.invoke(Wrapper.android.kt:140)
        at androidx.compose.ui.platform.WrappedComposition$setContent$1.invoke(Wrapper.android.kt:131)
        at androidx.compose.ui.platform.AndroidComposeView.setOnViewTreeOwnersAvailable(AndroidComposeView.android.kt:907)
        at androidx.compose.ui.platform.WrappedComposition.setContent(Wrapper.android.kt:131)
        at androidx.compose.ui.platform.WrappedComposition.onStateChanged(Wrapper.android.kt:182)
        at androidx.lifecycle.LifecycleRegistry$ObserverWithState.dispatchEvent(LifecycleRegistry.java:354)
        at androidx.lifecycle.LifecycleRegistry.addObserver(LifecycleRegistry.java:196)
        at androidx.compose.ui.platform.WrappedComposition$setContent$1.invoke(Wrapper.android.kt:138)
        at androidx.compose.ui.platform.WrappedComposition$setContent$1.invoke(Wrapper.android.kt:131)
        at androidx.compose.ui.platform.AndroidComposeView.onAttachedToWindow(AndroidComposeView.android.kt:994)
        at android.view.View.dispatchAttachedToWindow(View.java:20626)
        at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3514)
        at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3521)
        at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3521)
        at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3521)
        at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3521)
        at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3521)
        at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3521)
        at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2726)
        at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:2206)
        at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:8763)
        at android.view.Choreographer$CallbackRecord.run(Choreographer.java:1352)
        at android.view.Choreographer.doCallbacks(Choreographer.java:1149)
        at android.view.Choreographer.doFrame(Choreographer.java:1049)
        at android.view.Choreographer$FrameHandler.handleMessage(Choreographer.java:1275)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loop(Looper.java:233)
        at android.app.ActivityThread.main(ActivityThread.java:8068)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:631)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:978)

@huaweikai
Copy link

@owenlejeune ok,i sent an email to you.

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

4 participants