lincollincol / compose-audiowaveform

Audio waveform library for Jetpack Compose
Apache License 2.0
204 stars 12 forks source link

App Crash - java.lang.NoSuchMethodError: No static method drawRoundRect- #9

Closed yosuke65 closed 1 year ago

yosuke65 commented 1 year ago
    java.lang.NoSuchMethodError: No static method drawRoundRect-ZuiqVtQ$default(Landroidx/compose/ui/graphics/drawscope/DrawScope;Landroidx/compose/ui/graphics/Brush;JJJFLandroidx/compose/ui/graphics/drawscope/DrawStyle;Landroidx/compose/ui/graphics/ColorFilter;IILjava/lang/Object;)V in class Landroidx/compose/ui/graphics/drawscope/DrawScope; or its super classes (declaration of 'androidx.compose.ui.graphics.drawscope.DrawScope' appears in /data/app/~~wme9RWI_TEWRMheotXYODg==/jp.tripmate.slo.dev-dqTZEZknICnb5A4bkff_CQ==/base.apk)
        at com.linc.audiowaveform.AudioWaveformKt$AudioWaveform$2.invoke(AudioWaveform.kt:100)
        at com.linc.audiowaveform.AudioWaveformKt$AudioWaveform$2.invoke(AudioWaveform.kt:74)

Hi, I'm facing above crash. Is this a bug?

lincollincol commented 1 year ago

@yosuke65 Hello! Make sure you add the dependencies listed below

implementation "androidx.compose.ui:ui:$compose_version"
implementation "androidx.compose.material:material:$compose_version"
yosuke65 commented 1 year ago

@lincollincol Yes, I have those already. It's running but not working in generated apk.

lincollincol commented 1 year ago

@yosuke65 Ok, got it. Please, can you share build.gradle file with me. I'd like to check dependencies and config. Maybe it's related to the jetpack compose library version

Boriswp commented 1 year ago

Hello @lincollincol Have the same error, using compose and material version 1.3.1, but only if I BUILD apk file, when I just run it on the same device everything work.

lincollincol commented 1 year ago

@yosuke65 @Boriswp Please, try this build of the sample app. I have generated this build with R8 as well. Let me know if you have the same issue with my build. audiowaveform_sample_1-release.apk.zip

Boriswp commented 1 year ago

Yes, your build work. This build from your app example? Hmm I solve my problem by directly download your library files into my projects. Everything works. Why so happened if importing them — I don't know.

lincollincol commented 1 year ago

@Boriswp Great! I'd like to take a look at build config. It probably can be related to compose config or something like that. Can you share build.gradle file with me? Or maybe you have a project on github?

Boriswp commented 1 year ago

I'm afraid that won't be necessary, to reproduce this I downloaded your example app and used your gradle file with the only difference... androidWave I used not locally but via implementation 'com.github.lincollincol:compose-audiowaveform:1.0.1'. And unfortunately when you build app in this way you have this bug)

lincollincol commented 1 year ago

@Boriswp I created a sample project and added compose-audiowaveform lib as you described in the last reply.

Here are generated release and debug apk's: app-debug.apk.zip app-release.apk.zip

Also, activity file with AudioWaveform example and build.gradle files and:

MainActivity.kt

package com.linc.composesample

import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.material.MaterialTheme
import androidx.compose.material.Surface
import androidx.compose.runtime.*
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.SolidColor
import com.linc.audiowaveform.AudioWaveform
import com.linc.composesample.ui.theme.ComposeSampleTheme

class MainActivity : ComponentActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        val amps = buildList {
            repeat(100) {
                add(it)
            }
        }
        setContent {
            ComposeSampleTheme {
                // A surface container using the 'background' color from the theme
                Surface(
                    modifier = Modifier.fillMaxSize(),
                    color = MaterialTheme.colors.background
                ) {
                    var waveformProgress by remember { mutableStateOf(0F) }
                    AudioWaveform(
                        amplitudes = amps,
                        progressBrush = SolidColor(Color.Magenta),
                        waveformBrush = SolidColor(Color.LightGray),
                        progress = waveformProgress,
                        onProgressChange = { waveformProgress = it }
                    )
                }
            }
        }
    }
}

build.gradle (app)

plugins {
    id 'com.android.application'
    id 'org.jetbrains.kotlin.android'
}

android {
    namespace 'com.linc.composesample'
    compileSdk 33

    defaultConfig {
        applicationId "com.linc.composesample"
        minSdk 24
        targetSdk 33
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
        vectorDrawables {
            useSupportLibrary true
        }
    }

    signingConfigs {
        release {
            storeFile file("<key.jks>")
            storePassword '<password>'
            keyAlias = '<alias>'
            keyPassword '<password>'
        }
    }

    buildTypes {
        debug {
            minifyEnabled false
            applicationIdSuffix = ".beta"
        }
        release {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
            signingConfig signingConfigs.release
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    kotlinOptions {
        jvmTarget = '1.8'
    }
    buildFeatures {
        compose true
    }
    composeOptions {
        kotlinCompilerExtensionVersion '1.2.0'
    }
    packagingOptions {
        resources {
            excludes += '/META-INF/{AL2.0,LGPL2.1}'
        }
    }
}

dependencies {

    implementation 'androidx.core:core-ktx:1.7.0'
    implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.3.1'
    implementation 'androidx.activity:activity-compose:1.3.1'
    implementation "androidx.compose.ui:ui:$compose_ui_version"
    implementation "androidx.compose.ui:ui-tooling-preview:$compose_ui_version"
    implementation 'androidx.compose.material:material:1.2.0'
    testImplementation 'junit:junit:4.13.2'
    androidTestImplementation 'androidx.test.ext:junit:1.1.3'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
    androidTestImplementation "androidx.compose.ui:ui-test-junit4:$compose_ui_version"
    debugImplementation "androidx.compose.ui:ui-tooling:$compose_ui_version"
    debugImplementation "androidx.compose.ui:ui-test-manifest:$compose_ui_version"

    implementation 'com.github.lincollincol:compose-audiowaveform:1.0.1'
    implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.4.0'
}

build.gradle (project)

buildscript {
    ext {
        compose_ui_version = '1.2.0'
    }
}// Top-level build file where you can add configuration options common to all sub-projects/modules.
plugins {
    id 'com.android.application' version '7.4.1' apply false
    id 'com.android.library' version '7.4.1' apply false
    id 'org.jetbrains.kotlin.android' version '1.7.0' apply false
}

settings.gradle (project)

pluginManagement {
    repositories {
        google()
        mavenCentral()
        gradlePluginPortal()
    }
}
dependencyResolutionManagement {
    repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
    repositories {
        google()
        mavenCentral()
        maven { url 'https://jitpack.io' }
    }
}
rootProject.name = "ComposeSample"

include ':app'