I am developing a flutter project. I am trying to use a descendant of Theme.AppCompat for my activity. Below is my code.
/android/app/src/main/res/values/styles.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- Theme applied to the Android Window while the process is starting when the OS's Dark Mode setting is off -->
<style name="LaunchTheme" parent="#android:style/Theme.Light.NoTitleBar">
<!-- Show a splash screen on the activity. Automatically removed when
Flutter draws its first frame -->
<item name="android:windowBackground">#drawable/launch_background</item>
</style>
<!-- Theme applied to the Android Window as soon as the process has started.
This theme determines the color of the Android Window while your
Flutter UI initializes, as well as behind your Flutter UI while its
running.
This Theme is only used starting with V2 of Flutter's Android embedding. -->
<style name="NormalTheme" parent="Theme.MaterialComponents">
<item name="android:windowBackground">?android:colorBackground</item>
</style>
</resources>
/android/app/src/main/res/values-night/styles.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- Theme applied to the Android Window while the process is starting when the OS's Dark Mode setting is on -->
<style name="LaunchTheme" parent="#android:style/Theme.Black.NoTitleBar">
<!-- Show a splash screen on the activity. Automatically removed when
Flutter draws its first frame -->
<item name="android:windowBackground">#drawable/launch_background</item>
</style>
<!-- Theme applied to the Android Window as soon as the process has started.
This theme determines the color of the Android Window while your
Flutter UI initializes, as well as behind your Flutter UI while its
running.
This Theme is only used starting with V2 of Flutter's Android embedding. -->
<style name="NormalTheme" parent="Theme.MaterialComponents">
<item name="android:windowBackground">?android:colorBackground</item>
</style>
</resources>
/android/app/build.gradle
def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
localPropertiesFile.withReader('UTF-8') { reader ->
localProperties.load(reader)
}
}
def flutterRoot = localProperties.getProperty('flutter.sdk')
if (flutterRoot == null) {
throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
}
def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
if (flutterVersionCode == null) {
flutterVersionCode = '1'
}
def flutterVersionName = localProperties.getProperty('flutter.versionName')
if (flutterVersionName == null) {
flutterVersionName = '1.0'
}
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
apply plugin: 'com.google.gms.google-services'
def keystoreProperties = new Properties()
def keystorePropertiesFile = rootProject.file('key.properties')
if (keystorePropertiesFile.exists()) {
keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
}
android {
compileSdkVersion 31
sourceSets {
main.java.srcDirs += 'src/main/kotlin'
}
defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.xxx.xxx"
minSdkVersion 23
targetSdkVersion 30
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
}
signingConfigs {
release {
keyAlias keystoreProperties['keyAlias']
keyPassword keystoreProperties['keyPassword']
storeFile keystoreProperties['storeFile'] ? file(keystoreProperties['storeFile']) : null
storePassword keystoreProperties['storePassword']
}
}
buildTypes {
release {
// TODO: Add your own signing config for the release build.
// Signing with the debug keys for now, so `flutter run --release` works.
minifyEnabled false
shrinkResources false
signingConfig signingConfigs.release
}
}
}
flutter {
source '../..'
}
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation platform('com.google.firebase:firebase-bom:28.4.2')
implementation 'com.google.firebase:firebase-analytics'
implementation 'com.google.firebase:firebase-firestore:24.0.2'
}
When I run my code, I get the following error.
* What went wrong:
Execution failed for task ':app:processDebugResources'.
> A failure occurred while executing com.android.build.gradle.internal.res.LinkApplicationAndroidResourcesTask$TaskAction
> Android resource linking failed
ERROR:AAPT: error: resource style/Theme.MaterialComponents (aka com.peresiaapp.peresia_customer:style/Theme.MaterialComponents) not found.
error: resource style/Theme.MaterialComponents (aka com.peresiaapp.peresia_customer:style/Theme.MaterialComponents) not found.
error: failed linking references.
What went wrong here?
From document https://m2.material.io/develop/android/docs/getting-started
Material Components for Android is available through Google's Maven Repository. To use it:
...
Step 3: Add the library to the dependencies section:
dependencies {
// ...
implementation 'com.google.android.material:material:<version>'
// ...
}
Related
My Flutter project works fine, I can build it as Android app with VisualStudio Code. With AndroidStudio I am able to build the Android app if I open only the android folder and build the Android app as android project.
But if I open the whole Flutter project in AndroidStudio and try to build it for Android (iOS works fine) I get this error:
Exception: Gradle build failed to produce an .apk file. It's likely that this file was generated under .../build, but the tool couldn't find it.
Seems like an IDE bug, is there anyone with a solution for me?
Android Studio version : Android Studio Electric Eel | 2022.1.1 (Build #AI-221.6008.13.2211.9477386, built on January 11, 2023)
Update:
app/build.gradle
def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
localPropertiesFile.withReader('UTF-8') { reader ->
localProperties.load(reader)
}
}
def flutterRoot = localProperties.getProperty('flutter.sdk')
if (flutterRoot == null) {
throw new FileNotFoundException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
}
def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
def flutterVersionName = localProperties.getProperty('flutter.versionName')
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
android {
compileSdkVersion 33
sourceSets {
main.java.srcDirs += 'src/main/kotlin'
}
flavorDimensions "distribute"
productFlavors {
appCenter {
dimension "distribute"
}
googlePlay {
dimension "distribute"
}
}
lintOptions {
disable 'InvalidPackage'
checkReleaseBuilds false
}
defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "myId"
minSdkVersion 21
targetSdkVersion 33
versionCode 3
versionName flutterVersionName
}
buildTypes {
release {
// TODO: Add your own signing config for the release build.
// Signing with the debug keys for now, so `flutter run --release` works.
signingConfig signingConfigs.debug
}
}
}
flutter {
source '../..'
}
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
}
You have no default flavor defined, so you need to specify flavor to build. From command line:
flutter run --flavor appCenter (or googlePlay)
In Android Studio, go to Run->Edit configurations and set flavor to build (in your case appCenter or googlePlay. You can also add new configuration to be able to swith between them to build different flavor.
I have this error that says I need to override some values in one the Android.xml files. Despite changing the values, as suggested, I keep getting the same error. At times the values in the AndroidManifest.xml wouldn't even change even after saving.
Here below you'll see the error message when building:
What went wrong:
Execution failed for task ':cloud_firestore:processDebugAndroidTestManifest'.
Manifest merger failed : uses-sdk:minSdkVersion 16 cannot be smaller than version 23 declared in library [com.google.firebase:firebase-firestore:24.1.2] C:\Users\DELL.gradle\caches\transforms-3\2bfce4225340219067212fe3be9c89b6\transformed\jetified-firebase-firestore-24.1.2\AndroidManifest.xml as the library might be using APIs not available in 16
Suggestion: use a compatible library with a minSdk of at most 16,
or increase this project's minSdk version to at least 23,
or use tools:overrideLibrary="com.google.firebase.firestore" to force usage (may lead to runtime failures)
The build.gradle file:
def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
localPropertiesFile.withReader('UTF-8') { reader ->
localProperties.load(reader)
}
}
def flutterRoot = localProperties.getProperty('flutter.sdk')
if (flutterRoot == null) {
throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
}
def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
if (flutterVersionCode == null) {
flutterVersionCode = '1'
}
def flutterVersionName = localProperties.getProperty('flutter.versionName')
if (flutterVersionName == null) {
flutterVersionName = '1.0'
}
apply plugin: 'com.android.application'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
android {
compileSdkVersion 32
//buildToolsVersion "30.0.2"
lintOptions {
//disable 'InvalidPackage'
abortOnError false
}
sourceSets {
main.java.srcDirs += 'src/main/kotlin'
}
defaultConfig {
configurations.all {
resolutionStrategy { force 'androidx.work:work-runtime:2.6.0' }
}
applicationId "com.praveeshramroop.athena"
minSdkVersion 23
targetSdkVersion 32
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
multiDexEnabled true
}
buildTypes {
release {
// TODO: Add your own signing config for the release build.
// Signing with the debug keys for now, so `flutter run --release` works.
signingConfig signingConfigs.debug
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
The AndroidManifest.xml file:
<?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.google.firebase.firestore"
android:versionName="24.1.2" >
<uses-sdk
android:minSdkVersion="23"
android:targetSdkVersion="32"
tools:overrideLibrary="com.google.firebase.firestore"/>
<!-- Although the *SdkVersion is captured in gradle build files, this is required for non gradle builds -->
<!-- <uses-sdk android:minSdkVersion="14" /> -->
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<application>
<service
android:name="com.google.firebase.components.ComponentDiscoveryService"
android:exported="false" >
<meta-data
android:name="com.google.firebase.components:com.google.firebase.firestore.FirestoreRegistrar"
android:value="com.google.firebase.components.ComponentRegistrar" />
</service>
</application>
</manifest>
As you can see, I've done everything as recommended. The values are correct in both the build.gradle and AndroidManifest.xml file. But still getting the same error, don't know why. Anything else I should do? If any additional information required, do let me know.
I have a Flutter App in the Playstore and if you have Android 12, it will just pop an Error Message:
"AppName cannot be installed"
My Flutter version is 2.5.0
I would expect the app to be installable on Android 12 because of my settings. Are there any òther reasons this could fail?
This is my build.grade:
def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
localPropertiesFile.withReader('UTF-8') { reader ->
localProperties.load(reader)
}
}
def flutterRoot = localProperties.getProperty('flutter.sdk')
if (flutterRoot == null) {
throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
}
def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
if (flutterVersionCode == null) {
flutterVersionCode = '25'
}
def flutterVersionName = localProperties.getProperty('flutter.versionName')
if (flutterVersionName == null) {
flutterVersionName = '1.1.0'
}
def keystoreProperties = new Properties()
def keystorePropertiesFile = rootProject.file('key.properties')
if (keystorePropertiesFile.exists()) {
keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
}
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
// apply plugin: 'com.google.gms.google-services'
android {
compileSdkVersion 31
sourceSets {
main.java.srcDirs += 'src/main/kotlin'
}
lintOptions {
disable 'InvalidPackage'
}
defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "myAppID"
minSdkVersion 21
targetSdkVersion 31
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
}
signingConfigs {
release {
keyAlias keystoreProperties['keyAlias']
keyPassword keystoreProperties['keyPassword']
storeFile keystoreProperties['storeFile'] ? file(keystoreProperties['storeFile']) : null
storePassword keystoreProperties['storePassword']
}
}
buildTypes {
release {
signingConfig signingConfigs.release
//signingConfig signingConfigs.debug
minifyEnabled true
useProguard true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
debug{
minifyEnabled true
useProguard true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
flutter {
source '../..'
}
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
//def multidex_version = "2.0.1"
//implementation 'androidx.multidex:multidex:$multidex_version'
implementation 'com.android.support:multidex:1.0.3'
}
apply plugin: 'com.google.gms.google-services'
Flutter Doctor:
Installing this on an Android 12 Emulator, the install fails with this message:
After I did add this value as true to my appmanifest, I started it again and I have an endless install loading icon in visual studio code. I have the app on the device, but it will close immidiately after tapping on it
You have to set android:exported to any <activity>, <activity-alias>,<service>, or <receiver> components that have <intent-filter>s declared in the app’s AndroidManifest.xml file.
ALSO!!!!
You have to do the same for every package you use. I would advice NOT doing it manually as this could get modified by calling something like "Pub clear cache" and instead try to update your packages to the latest version.
https://medium.com/androiddevelopers/lets-be-explicit-about-our-intent-filters-c5dbe2dbdce0
When I was stuck for this issue, did not found anything helpful on the web: not many people seems to encountered this.
I tried creating fresh new flutter app, copying its /android folder to my old project; setting android:exported for in AndroidManifest.xml: none of helped for running my app on Android 12 device. (Also there were some Android 11 devices, all of them being SAMSUNG, that our app, of which target sdk was set to 31, could not be installed.
Finally setting targetSdkVersion as 30 and compileSdkVersion as 30, fixed the issue.
SDK version 30 and Android 12? Weird.
just follow steps :
1 set targetSdkVersion and compileSdkVersion 32
2 open AndroidManifest.xml , in application tag add this -
usesCleartextTraffic="true"
androidSupportRtl="true"
3 set android:exported="true" in activity
I can't connect my app to Google Firebase and I need to see somethings in that build gradle file. When I open the app level build gradle, I get errors, I am trying to connect my app to Google Firebase but when I open my app normally, I see no errors at all and everything is going just fine and I can still run my app on the Android Emulator, but when I go ahead and open the file, errors start to pop up and I am unable to run my app, here is my app level build gradle for Android:
def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
localPropertiesFile.withReader('UTF-8') { reader ->
localProperties.load(reader)
}
}
def flutterRoot = localProperties.getProperty('flutter.sdk')
if (flutterRoot == null) {
throw new FileNotFoundException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
}
def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
if (flutterVersionCode == null) {
flutterVersionCode = '1'
}
def flutterVersionName = localProperties.getProperty('flutter.versionName')
if (flutterVersionName == null) {
flutterVersionName = '1.0'
}
apply plugin: 'com.android.application'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
android {
compileSdkVersion 29
lintOptions {
disable 'InvalidPackage'
}
defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "co.appbrewery.flash_chat"
minSdkVersion 16
targetSdkVersion 29
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
multiDexEnabled true
}
buildTypes {
release {
// TODO: Add your own signing config for the release build.
// Signing with the debug keys for now, so `flutter run --release` works.
signingConfig signingConfigs.debug
}
}
}
flut
ter {
source '../..'
}
dependencies {
implementation 'androidx.multidex:multidex:2.0.0'
}
I am unable to understand the problem. Please help.
You can't edit the gradle files in the flutter project. You have to click on Tools --> Flutter --> Open Android Module in Android Studio. Then you can edit the graddle, run the app and come back to the flutter project with no errors.
works
Goto : Tools -> Flutter -> Open Flutter Module in Android Studio -> Make changes in build gradle
I've been testing my first Flutter app on iOS and its going well. Now I run it for the first time in an Android simulator and I get this error.
07-18 11:42:10.757 4264-4264/? E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.akamojo.liga, PID: 4264
java.lang.RuntimeException: Unable to instantiate application com.akamojo.liga.liga: java.lang.ClassNotFoundException: Didn't find class "com.akamojo.liga.liga" on path: DexPathList[[zip file "/data/app/com.akamojo.liga-1/base.apk"],nativeLibraryDirectories=[/data/app/com.akamojo.liga-1/lib/x86, /data/app/com.akamojo.liga-1/base.apk!/lib/x86, /vendor/lib, /system/lib]]
at android.app.LoadedApk.makeApplication(LoadedApk.java:578)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4680)
at android.app.ActivityThread.-wrap1(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1405)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
It looks suspicious to me that is says it is looking for the class "com.akamojo.liga.liga". Is it correct? My applicationId is "com.akamojo.liga". Is the Flutter framework creating a starting class called "liga"?
Here is build.gradle.
def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
localPropertiesFile.withReader('UTF-8') { reader ->
localProperties.load(reader)
}
}
def flutterRoot = localProperties.getProperty('flutter.sdk')
if (flutterRoot == null) {
throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
}
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
def keystorePropertiesFile = rootProject.file("key.properties")
def keystoreProperties = new Properties()
keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
android {
compileSdkVersion 27
sourceSets {
main.java.srcDirs += 'src/main/kotlin'
}
lintOptions {
disable 'InvalidPackage'
}
defaultConfig {
applicationId "com.akamojo.liga"
minSdkVersion 16
targetSdkVersion 27
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
signingConfigs {
release {
keyAlias keystoreProperties['keyAlias']
keyPassword keystoreProperties['keyPassword']
storeFile file(keystoreProperties['storeFile'])
storePassword keystoreProperties['storePassword']
}
}
buildTypes {
release {
signingConfig signingConfigs.release
}
}
}
flutter {
source '../..'
}
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
}
Here is the AndroidManifest.xml file.
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.akamojo.liga">
<!-- The INTERNET permission is required for development. Specifically,
flutter needs it to communicate with the running application
to allow setting breakpoints, to provide hot reload, etc.
-->
<uses-permission android:name="android.permission.INTERNET"/>
<!-- io.flutter.app.FlutterApplication is an android.app.Application that
calls FlutterMain.startInitialization(this); in its onCreate method.
In most cases you can leave this as-is, but you if you want to provide
additional functionality it is fine to subclass or reimplement
FlutterApplication and put your custom class here. -->
<application
android:name="liga"
android:label="liga"
android:icon="#mipmap/ic_launcher">
<activity
android:name=".MainActivity"
android:launchMode="singleTop"
android:theme="#style/LaunchTheme"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|layoutDirection|fontScale|screenLayout|density"
android:hardwareAccelerated="true"
android:windowSoftInputMode="adjustResize">
<!-- This keeps the window background of the activity showing
until Flutter renders its first frame. It can be removed if
there is no splash screen (such as the default splash screen
defined in #style/LaunchTheme). -->
<meta-data
android:name="io.flutter.app.android.SplashScreenUntilFirstFrame"
android:value="true" />
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
</application>
</manifest>
Add the following code in your mainActivity.kt file
override fun onCreate(savedInstanceState: Bundle?) {
FlutterMain.startInitialization(this); //Added line
super.onCreate(savedInstanceState)
GeneratedPluginRegistrant.registerWith(this)
}
My app was working but after Dart plugin update I started to get this error.
java.lang.RuntimeException: Unable to instantiate activity ComponentInfo com.package.name.MainActivity
In my case it was because of incompatibility of Dart and Flutter plugin.
I ran flutter upgrade command and app starting working normal again.
So make sure to keep both Dart and Flutter plugins updated.
First,
File>Project Structure> Select Project SDK Latest API Platform and go modules(dependencies) and select Latest API Platform, apply,OK.
Second,
in build-gradle => compileSdkVersion 28,targetSdkVersion 28 to change 30.
Third,
in build-gradle => GradleException to change FileNotFoundException
thats it.
I had the same experience then I changed that package name of the project to android> app> src> main> MainActivity.kt or MainActivity.java and change your package com.example.name replace example with another.
The name which you have written in AndroidManiFest and app-level build file