Auties00 / Cobalt

Standalone unofficial fully-featured Whatsapp Web and Mobile API for Java and Kotlin
MIT License
616 stars 180 forks source link

Add support for Android #281

Closed malinkang closed 9 months ago

malinkang commented 1 year ago

AGP Version:8.0.1 Gradle Version:8.0 image image

build.gradle

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

android {
    namespace 'com.example.whatsapp4j'
    compileSdk 33

    defaultConfig {
        applicationId "com.example.whatsapp4j"
        minSdk 26
        targetSdk 33
        versionCode 1
        versionName "1.0"

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

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_17
        targetCompatibility JavaVersion.VERSION_17
    }
    kotlinOptions {
        jvmTarget = '17'
    }
    buildFeatures {
        compose true
    }
    composeOptions {
        kotlinCompilerExtensionVersion '1.4.3'
    }
    packagingOptions {
        resources {
            excludes += '/META-INF/{AL2.0,LGPL2.1}'
            excludes += '/META-INF/DEPENDENCIES'
            excludes += '/META-INF/LICENSE.md'
            excludes += '/META-INF/NOTICE.md'
        }
    }
}

dependencies {
    implementation 'com.github.auties00:whatsappweb4j:3.3.1'
    implementation 'androidx.core:core-ktx:1.8.0'
    implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.3.1'
    implementation 'androidx.activity:activity-compose:1.5.1'
    implementation platform('androidx.compose:compose-bom:2022.10.00')
    implementation 'androidx.compose.ui:ui'
    implementation 'androidx.compose.ui:ui-graphics'
    implementation 'androidx.compose.ui:ui-tooling-preview'
    implementation 'androidx.compose.material3:material3'
    testImplementation 'junit:junit:4.13.2'
    androidTestImplementation 'androidx.test.ext:junit:1.1.3'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
    androidTestImplementation platform('androidx.compose:compose-bom:2022.10.00')
    androidTestImplementation 'androidx.compose.ui:ui-test-junit4'
    debugImplementation 'androidx.compose.ui:ui-tooling'
    debugImplementation 'androidx.compose.ui:ui-test-manifest'
}
Auties00 commented 1 year ago

I'm gonna guess that R8 doesn't support preview features, that's why it's crashing

Auties00 commented 1 year ago

the bug isn't too hard to solve, i would just need to refactor the library to not use preview features. I only use the enhanced switch with pattern matching so it shouldn't be that hard

Auties00 commented 1 year ago

@malinkang I've pushed a commit without preview features, see if it's fixed

malinkang commented 1 year ago

It seems like this issue has been resolved, but another error has occurred.

2: Task failed with an exception.

==============================================================================

BUILD FAILED in 480ms

Auties00 commented 1 year ago

this seems like an R8 bug for records

Auties00 commented 9 months ago

It should work now , at least when Java 21 is enabled