saki4510t / UVCCamera

library and sample to access to UVC web camera on non-rooted Android device
2.96k stars 1.19k forks source link

java.lang.RuntimeException: Unable to start activity ComponentInfo : java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity #692

Closed Germansdev closed 8 months ago

Germansdev commented 8 months ago

Kotlin, AndroidStudio Flamingo

Im following App to sync Realm to MongoAtlas https://github.com/mongodb-developer/EmojiGarden/tree/main

I got the following error. I update realm to avoid error transform and also include tools:replace="android:theme" in my manifest following some suggestions from others. I couldn´t solve this yet and i have no idea how to solve it. Thanks for any suggest.

FATAL EXCEPTION: main Process: com.example.emojigarden, PID: 17315 java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.emojigarden/com.example.emojigarden.MainActivity}: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity. at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3506) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3681) at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85) 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:2130) at android.os.Handler.dispatchMessage(Handler.java:106) at android.os.Looper.loop(Looper.java:250) at android.app.ActivityThread.main(ActivityThread.java:7803) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:958) Caused by: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity. at androidx.appcompat.app.AppCompatDelegateImpl.createSubDecor(AppCompatDelegateImpl.java:846) at androidx.appcompat.app.AppCompatDelegateImpl.ensureSubDecor(AppCompatDelegateImpl.java:809) at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:705) at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:207) at androidx.activity.compose.ComponentActivityKt.setContent(ComponentActivity.kt:67) at androidx.activity.compose.ComponentActivityKt.setContent$default(ComponentActivity.kt:48) at com.example.emojigarden.MainActivity.onCreate(MainActivity.kt:35) at android.app.Activity.performCreate(Activity.java:8104) at android.app.Activity.performCreate(Activity.java:8088) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1309) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3479) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3681)  at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85)  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:2130)  at android.os.Handler.dispatchMessage(Handler.java:106)  at android.os.Looper.loop(Looper.java:250)  at android.app.ActivityThread.main(ActivityThread.java:7803)  at java.lang.reflect.Method.invoke(Native Method)  at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:958) 

My Manifest: <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" package="com.example.emojigarden">

<uses-permission android:name="android.permission.INTERNET"/>

<application
    android:name=".EmojiGardenApplication"
    android:allowBackup="true"
    tools:replace="android:theme"
    android:dataExtractionRules="@xml/data_extraction_rules"
    android:fullBackupContent="@xml/backup_rules"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:roundIcon="@mipmap/ic_launcher_round"
    android:supportsRtl="true"
    android:theme="@style/Theme.AppCompat.EmojiGarden"
    tools:targetApi="31">
    <activity
        android:name=".MainActivity"
        android:exported="true"
        android:label="@string/app_name"
        android:theme="@style/Theme.AppCompat.EmojiGarden">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

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


My BuildGradle app: plugins { id 'com.android.application' id 'kotlin-android' id 'kotlin-kapt' id 'realm-android' }

realm { syncEnabled = true }

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

defaultConfig {
    applicationId "com.example.emojigarden"
    minSdk 25
    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_11
    targetCompatibility JavaVersion.VERSION_11
}
kotlinOptions {
    jvmTarget = '11'
}
buildFeatures {
    compose true
}

composeOptions {
    kotlinCompilerExtensionVersion '1.3.2'
}

packagingOptions {
    resources {
        excludes += '/META-INF/{AL2.0,LGPL2.1}'
    }
}

}

dependencies { implementation 'androidx.core:core-ktx:1.6.0' implementation 'androidx.appcompat:appcompat:1.3.1' implementation 'com.google.android.material:material:1.4.0'

// For Jetpack Compose
implementation "androidx.compose.ui:ui:$compose_version"
implementation "androidx.compose.material:material:$compose_version"
implementation "androidx.compose.ui:ui-tooling:$compose_version"
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.3.1'
implementation 'androidx.activity:activity-ktx:1.3.0' // also ViewModels
implementation 'androidx.activity:activity-compose:1.3.0'

// For the viewModel function that imports them into activities implementation 'androidx.activity:activity-ktx:1.3.0'

// For the ViewModelScope if using Coroutines in the ViewModel implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.3.1' implementation "androidx.lifecycle:lifecycle-viewmodel-compose:1.0.0-alpha07"

implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.4'

implementation 'io.realm:realm-gradle-plugin:10.10.1'
implementation 'androidx.wear.compose:compose-material:1.1.2'

}

My BuildGradle (Project)

/ Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { ext { compose_version = '1.0.0' kotlin_ext = '1.5.10'

}
repositories {
    mavenCentral()
}

dependencies {
    //classpath "io.realm:realm-gradle-plugin:10.11.1"// with this error transform deprecated api
    classpath "io.realm:realm-gradle-plugin:10.15.1"
}

}

plugins { id 'com.android.application' version '8.0.1' apply false id 'com.android.library' version '8.0.1' apply false id 'org.jetbrains.kotlin.android' version '1.7.20' apply false id "org.jetbrains.kotlin.kapt" version "1.6.20" apply false id 'io.realm.kotlin' version '1.6.1' apply false

}

task clean(type: Delete) { delete rootProject.buildDir }

Germansdev commented 8 months ago

I solved by myself the issue, changing the Theme in manifest and changing in xml file inside resources following the code in Github.