Flutter App not installable from Google store for Android 12 despite being set to targetSDK 31
Asked Answered
C

3

8

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: enter image description here

Installing this on an Android 12 Emulator, the install fails with this message:

enter image description here

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

Craftwork answered 9/11, 2021 at 11:52 Comment(4)
Did you tried to install your app in release mode on an Android 12 device by running: flutter run --release and provide the post by logsWayward
same thing happening with me +1Siderosis
did you get any lead regarding this?Siderosis
I just created a new project and moved my files over gradually to solve this problem. That was way less stressful and took me only 40 minutes or soCraftwork
C
11

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

Captivity answered 12/11, 2021 at 5:41 Comment(4)
thanks , but we have so much plugins that not add exported value, what should i do, fock them all and modify it?Menell
I would update all the problem packages that you can to the latest version. If you're still having problems I would update them manually but make SURE you don't call "pub clear cache" after that as you will undo all of the manual changes.Captivity
Depending on where you are in the development process you could also copy the package from your pub cache and put it in your project folder and modify it there. Than all you'd have to do is point your pubspec.yaml dependencies like so flutter_chat_types: path: ./flutter_chat_types-3.1.2_HIJACKED. This will prevent your changes from being modified by the dart eco system. This takes a little more work, but will provide a little more security to your project.Captivity
Maybe it's better to write a script to do that?Quaky
C
4

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.

Cata answered 1/3, 2022 at 4:11 Comment(0)
C
0

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

Camp answered 19/8, 2022 at 6:42 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.