I need to do some thing like this: I have application with versionCode 10 after update I need to clear all cache in application's private storage directory. I want to do something in main's activity onCreate method like this:
if (versionCode == 11)
FileUtil.getInstance().clearSystemCache();
How can I get versionCode in my Activity or how can I solve this problem in a different way?
You can use BuildConfig.VERSION_CODE.
The Android Gradle plugin will automatically inject the VERSION_CODE constant into a BuildConfig class for you, along with a few other useful build configuration variables such as the version name and whether it is a debug build.
You can do this in your Activity
PackageInfo pInfo = getPackageManager().getPackageInfo(getPackageName(), 0);
String versionName = pInfo.versionName;
String versionCode = pInfo.versionCode;
Related
Non-fatal Exception:
io.flutter.plugins.firebase.crashlytics.FlutterError:
PlatformException(error,
MediaSource.Factory#setDrmSessionManagerProvider no longer handles
null by instantiating a new DefaultDrmSessionManagerProvider.
Explicitly construct and pass an instance in order to retain the old
behavior., null, java.lang.NullPointerException:
MediaSource.Factory#setDrmSessionManagerProvider no longer handles
null by instantiating a new DefaultDrmSessionManagerProvider.
Explicitly construct and pass an instance in order to retain the old
behavior.
It was working previously but now it's failing due to exoPlayer. Any idea how to fix this?
it happened when i added another audio package to pubpsec.yaml so i removed last added audio package and run flutter clean then it worked fine again
for the Android error, it tells you that you need to enable multiDex in your project, here is how
in android/app/build.gradle add this line multiDexEnabled = true in the defaultConfig
your defaultConfig should look something like this
defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.test.test"
minSdkVersion 21
targetSdkVersion 30
multiDexEnabled = true
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
regarding the iOS error it says
dependency were found, but they required a higher minimum deployment target.
so increase the minimum deployment target. you can find it in ios/flutter/AppFrameworkInfo.plist named MinimumOSVersion and looking like this
<key>MinimumOSVersion</key>
<string>9.0</string>
What went wrong:
Execution failed for task ':app:checkDebugAarMetadata'.
A failure occurred while executing com.android.build.gradle.internal.tasks.CheckAarMetadataWorkAction
The minCompileSdk (31) specified in a
dependency's AAR metadata (META-INF/com/android/build/gradle/aar-metadata.properties)
is greater than this module's compileSdkVersion (android-30).
Dependency: androidx.work:work-runtime:2.7.0-rc01.
AAR metadata file: C:\Users\100812.gradle\caches\transforms-2\files-2.1\8fcba37f766c3622d8dbd30df4e98577\work-runtime-2.7.0-rc01\META-INF\com\android\build\gradle\aar-metadata.properties.
you can find the compileSdkVersion under: android > app > build.gradle
android {
compileSdkVersion 31
...
}
Check with your configuration in android/app/src/build.gradle file
with new version of flutter compileSdk and targetSdkVersion are mention as below
android {
compileSdkVersion flutter.compileSdkVersion
.....
defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.example.app"
minSdkVersion flutter.minSdkVersion
targetSdkVersion flutter.targetSdkVersion
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
}
I had faced the same issue, In case you cloned a GitHub repository and then when you run that code this is the error that comes up(as it happened with me) then Solution :
Step 1 : Create a new flutter project at your local system
Step 2 : Copy the code given in main.dart file of stub project and paste it into main.dart file of your local project
Step 3 : Make an 'assets' folder in your local project
Step 4 : download asset-files from GitHub and put them into your local 'assets' folder
Step 5 : in your local pubspec.yaml file, add dependency for your 'assets' folder
Step 6 : Rename MyApp() in widget testing file to MaterialApp()
Hit save(in files other than pubspec.yaml), get all dependencies(in pubspec.yaml) and you're good to go
In short :
Copy the required code and the dependencies you want
Then Save the changes and run
Error was there in my case mainly because the Flutter V2 has many changes and the code was outdated.
Go to android/app/build.gradle
Change:
From: compileSdkVersion 29
To: compileSdkVersion 31
Please run, then press f you will notice the SDK is the wrong version.
npx react-native doctor
I setup my project for flavors build (Google & Huawei) according to this doc - https://developer.huawei.com/consumer/en/doc/development/AppGallery-connect-Guides/agc-config-flavor.
Here are my build scripts. I have tried including the signature in the release build with no change.
app build.gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.myapp.testapp"
}
flavorDimensions "platform"
productFlavors {
huawei {
versionCode 1712
versionName "1.7.12"
targetSdkVersion 29
minSdkVersion 26
buildTypes {
resValue("string", "ad_app_id", "103959507")
release {
resValue("string", "ad_id", "g87ta7hatb")
minifyEnabled true
proguardFiles 'proguard.cfg'
debuggable = true
}
debug {
resValue("string", "ad_id", "testf9tx29xur5")
debuggable = true
}
}
}
}
lintOptions {
checkReleaseBuilds false
// Or, if you prefer, you can continue to check for errors in release builds,
// but continue the build even when errors are found:
abortOnError false
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
buildToolsVersion '29.0.2'
}
dependencies {
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'androidx.recyclerview:recyclerview:1.1.0'
implementation 'androidx.cardview:cardview:1.0.0'
implementation 'com.google.android.material:material:1.2.1'
implementation 'androidx.arch.core:core-runtime:2.1.0'
implementation 'androidx.arch.core:core-common:2.1.0'
huaweiImplementation 'com.huawei.hms:ads-lite:13.4.32.300'
huaweiImplementation 'com.huawei.agconnect:agconnect-apms:1.3.1.300'
huaweiImplementation 'com.huawei.agconnect:agconnect-core:1.4.1.300'
huaweiImplementation 'com.huawei.agconnect:agconnect-crash:1.4.1.300'
huaweiImplementation 'com.huawei.hms:iap:5.0.1.300'
}
apply plugin: 'com.huawei.agconnect'
project build.gradle
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
jcenter()
maven {
url 'https://developer.huawei.com/repo/'
}
}
dependencies {
classpath 'com.android.tools.build:gradle:4.0.1'
classpath 'com.huawei.agconnect:agcp:1.3.0.300'
}
}
allprojects {
repositories {
jcenter()
google()
maven {
url 'https://developer.huawei.com/repo/'
}
}
}
The environment is failing with 60054: url is null.
The gradle build is also picking up the file location:
--W- The variant: huaweiRelease, Use the json file: /Users/xxx/Documents/myappGoogle/app/src/release/agconnect-services.json
I have tried the flavor tags and have tried placing the json file within the flavor directory as the post stated here - https://forums.developer.huawei.com/forumPortal/en/topicview?tid=0201313999391430187&fid=0101187876626530001. The file so far has been picked up when placed in the app directory, the src/debug(release) directories, and also in the src/flavor directories. I can clearly see in the build logs that the correct file is being found by the build script.
What's also odd to me is the documentation:
https://developer.huawei.com/consumer/en/doc/development/HMS-References/iap-ExceptionHandlingAndGeneralErrorCodes-v4
says that 60054 is iap is not supported in this country, but the actual code is returning 60054: url is null.
The error code being returned, iapApiException.getStatus()
is returning status.statusCode = 60054
and status.getStatusMessage = "url is null".
This is from isEnvReady which is in contradiction to the aforementioned documentation in which status code 60054 should be OrderStatusCode.ORDER_ACCOUNT_AREA_NOT_SUPPORTED
where as if this was actually a url error I would expect error 60001
OrderStatusCode.ORDER_STATE_PARAM_ERROR
or something along those lines.
I am thinking of the possibility with merge issue due to this document:
https://developer.huawei.com/consumer/en/doc/development/HMS-Guides/Environment_installation
The reason for my suspicion is that my AndroidManifest is clearly missing the appid that is supposed to be included through the scripts.
Am I missing something here? What is your suggestion or what else should I look into? Thanks.
1.Please check whether you have copy the agconnect-services.json file to the folder of each build type.
2.Please check whether you have modify configuration files to adapt to multiple flavors.
For details, see the documentation.
The result code of 60054 may be returned when HUAWEI IAP is supported by a country or region but there is a service error. In this case:
Please provide your appid to check the info.
Please provide full log: adb logcat >xxx.log to obtain it.
This is not the issue with the flavor build but it is the issue with using USA HUAWEI ID in testing. The right solution is a developer should create another non-USA HUAWEI ID and then log into the phone. After opening App Gallery App, change the Settings of country to a country that supports IAP(for example like UK). Remove USA SIM card and then use the IAP service after connecting to the changed country in the Setting using VPN.
I am using Azure DevOps and AppCenter(Distribution) for implementing my CICD. Based on the steps mentioned below I have implemented the both CI & CD tasks.
Thant means,
I will create the build using Azure Devops (VSTS) & Push that in to App Centre.
Steps I Follow
Here my doubt is,
How I can increment my Build and Version numbers while distributing these builds?
The easy way is to install Mobile App Tasks for iOS and Android extension for Azure DevOps. You get a task "Bump Version" (for Andriod and iOS).
The task change app's version name and code at build time.
Inputs:
sourcePath - Path to android manifest
versionCode - code number that must be an integer (put the build number variable, it's incremented automatically)
versionCodeOffset - a specific number to increment the version code
versionName- user visible name
printFile - output the file before and after changing variables
Another option is to install Colin's ALM Corner Build & Release Tools extension and use the Version Assemblies task following this detailed tutorial.
Check also this question & answer.
For anyone still looking for an alternative method, try modifying either the version number, version name or both in the module build.gradle file like below:
android {
defaultConfig {
applicationId 'com.sample.testapp'
minSdk 28
targetSdk 31
versionCode 2
versionName "2.2"
}
...
}
You can do almost anything with shell scripting, but I figured out to Automate Build numbering & App versioning for Android WITHOUT shell scripting while using Microsoft AppCenter CI/CD pipelines!
You can create 2 environment variables VERSION_CODE & VERSION_NAME and then use them in the build.gradle file like this:
versionCode System.getenv("VERSION_CODE") ? System.getenv("VERSION_CODE").toInteger() : 201
versionName System.getenv("VERSION_NAME") ? System.getenv("VERSION_NAME").toString() : "1.2.1"
More details in this article
Another option (if you don't want to install an extra plugin in Azure) is using the embedded counter function.
So basically you'll need to create the variable in the root of your pipeline, smth. like this:
versionCode: $[counter('Google_Play_version_offset', 100)]
Then it will autoincrement for each build - 100, 101, 102, etc.
In the gradle task you can pass this value with next:
- task: Gradle#2
inputs:
...
options: '-PversionCode=$(versionCode)'
...
Please also make sure to handle this option in the build.gradle file.
Flutter firebase auth UI have some issue, because of firebase_auth version miss match issue
My flutter app crashed and unable to identify an issue, after opening in an android studio, I got the issue and it is here
Caused by: java.lang.IllegalStateException: Default FirebaseApp is not initialized in this process com.mycom.mypetshop. Make sure to call FirebaseApp.initializeApp(Context) first.
at com.google.firebase.FirebaseApp.getInstance(com.google.firebase:firebase-common##16.0.2:240)
at com.google.firebase.auth.FirebaseAuth.getInstance(Unknown Source)
at io.flutter.plugins.firebaseauth.FirebaseAuthPlugin.<init>(FirebaseAuthPlugin.java:54)
at io.flutter.plugins.firebaseauth.FirebaseAuthPlugin.registerWith(FirebaseAuthPlugin.java:47)
at io.flutter.plugins.GeneratedPluginRegistrant.registerWith(GeneratedPluginRegistrant.java:20)
at com.vyapari2online.mypetshop.MainActivity.onCreate(MainActivity.java:11)
at android.app.Activity.performCreate(Activity.java:5990)
How to solve this?
In project 'app' a resolved Google Play services library dependency
depends on another at an exact version (e.g. "[15.0. 1]", but isn't
being resolved to that version. Behavior exhibited by the library will
be unknown.
Dependency failing: com.google.android.gms:play-services-flags:15.0.1
-> com.google.android.gms:play-services-basement#[
15.0.1], but play-services-basement version was 16.0.1.
The following dependencies are project dependencies that are direct or
have transitive dependencies that lead to the art ifact with the
issue.
-- Project 'app' depends on project 'firebase_auth' which depends onto com.google.firebase:firebase-auth#16.0.2
-- Project 'app' depends on project 'firebase_core' which depends onto com.google.firebase:firebase-core#16.0.4
-- Project 'app' depends on project 'cloud_firestore' which depends onto com.google.firebase:firebase-firestore#17.1.1
-- Project 'app' depends on project 'google_sign_in' which depends onto com.google.android.gms:play-services-auth#16.0.1
For extended debugging info execute Gradle from the command line with
./gradlew --info :app:assembleDebug to see the dep endency paths to
the artifact. This error message came from the google-services Gradle
plugin, report issues at https://
github.com/google/play-services-plugins and disable by adding
"googleServices { disableVersionCheck = false }" to your b uild.gradle
file.
#flutter_firebase_ui have a lot of issues #google please hire me, I can help your developers
Dependency Configuration
For the gradle issue, make sure your Android SDK and Firebase/Firestore plugins are compatible versions are compatible. Here's what worked for me:
dependencies {
classpath 'com.android.tools.build:gradle:3.2.1'
classpath 'com.google.gms:google-services:4.2.0'
classpath 'com.google.firebase:firebase-auth:16.0.5'
}
In the module/app build.gradle:
android {
compileSdkVersion 27
lintOptions {
disable 'InvalidPackage'
}
defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.timeswap.timeswapcore"
minSdkVersion 17
targetSdkVersion 27
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
multiDexEnabled true
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
...
}
Specifically, pay attention to the compileSdkVersion, targetSdkVersion, and the version numbers of google-services and firebase_auth. Fiddling with those numbers eventually led me to this config, and it may help you find your appropriate config.
Firebase or Firestore Initialization
As for the App initialization, I have this
Firestore firestore = Firestore.instance;
firestore.settings(timestampsInSnapshotsEnabled: true);
in my _initFirestore, which is called right after super.initState()
#override
void initState() {
super.initState();
_initFirestore();
checkCurrentUser();
}
Firebase (and all other Firebase plugins that I've used) is initialized similarly, but with the firebase_core: dependency instead of cloud_firestore: in pubspec.yaml.
For instance, from the flutter/plugins/packages/firebase_storage GitHub repo:
void main() async {
final FirebaseApp app = await FirebaseApp.configure(
name: 'test',
options: FirebaseOptions(
googleAppID: Platform.isIOS
? '1:159623150305:ios:4a213ef3dbd8997b'
: '1:159623150305:android:ef48439a0cc0263d',
gcmSenderID: '159623150305',
apiKey: 'AIzaSyChk3KEG7QYrs4kQPLP1tjJNxBTbfCAdgg',
projectID: 'flutter-firebase-plugins',
),
);
final FirebaseStorage storage = FirebaseStorage(
app: app, storageBucket: 'gs://flutter-firebase-plugins.appspot.com');
runApp(MyApp(storage: storage));
}
You can also use this Medium post as a guide to get started with the flutter Firebase Auth UI.
For future reference, you can navigate to flutter/plugins/packages/{package name} on Github and find main.dart inside of examples/lib for a demo. Feel free to leverage this to solve your dependency issue as well!
You need to initialize the FirebaseApp before using it. You can add it to your onCreate method.
#Override
public void onCreate() {
super.onCreate();
FirebaseApp.initializeApp(this);
}
Also make sure you have the dependency in your build.gradle
dependencies {
....
}
apply plugin: 'com.google.gms.google-services'
I also face same issue and solved by adding Facebook app id in AndroidManifest.xml
Try run Android app with Android studio you will get the error message