Flutter "Add 2 App" Android integration with adjustments to generated .android - android

I'm working on an Android app with 3+ years of Kotlin development and want to gradually migrate it to Flutter feature-by-feature. I use option B of the "add 2 app" integration where I depend on the module's source code. Features written Flutter are integrated into the native Android app with FlutterActivity or FlutterFragment. This worked great for the first feature however now I have an issue with migrating the second feature. The second feature requires the packages camera and firebase_ml_vision. Now the problem is that camera requires a min SDK of 21 but the generated Android code in .android sets the min SDK to 16. Additionally firebase_ml_vision requires initialization of Firebase which also needs to be added to .android. I'm thinking about adding .android to VCS and add the required changes however this is generated code. It gets removed when flutter clean is called and generated on flutter pub get. I would have to constantly adjust the generated code when Flutter changes/removes it :( .android only hosts the "skeleton" Android app which is started when the Flutter project is run from IDE (or command line). It is not the host app (the old, native app) where Firebase is already configured. However the .android app is used for quick development cycles. If I cannot use this anymore because of said limitations, I would always have to start the native Android app (host) and lose many benefits of Flutter like hot reload :( Has anyone come across the same problem?
Update:
In this article they clearly state that .android should not be modified or added to VCS. They even mention the camera module as an example. However this does not work and can be reproduced with a few simple steps:
Create a new module: flutter create --template=module --project-name example
cd example
Add camera plugin to pubspec.yaml
flutter pub get
Now running flutter build apk results in the following error:
/Users/sven/Development/example/.android/app/src/main/AndroidManifest.xml Error:
uses-sdk:minSdkVersion 16 cannot be smaller than version 21 declared in library [:camera] /Users/sven/.pub-cache/hosted/pub.dartlang.org/camera-0.5.8+11/android/build/intermediates/library_manifest/release/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 21,
or use tools:overrideLibrary="io.flutter.plugins.camera" to force usage (may lead to runtime failures)
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:processReleaseManifest'.
> Manifest merger failed : uses-sdk:minSdkVersion 16 cannot be smaller than version 21 declared in library [:camera] /Users/sven/.pub-cache/hosted/pub.dartlang.org/camera-0.5.8+11/android/build/intermediates/library_manifest/release/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 21,
or use tools:overrideLibrary="io.flutter.plugins.camera" to force usage (may lead to runtime failures)

I noticed you are facing 2 issues/ questions:
Minimum android sdk compatibility mismatch: Probably requires some work by the flutter team for a proper fix (I expected the flutter_module/build.gradle to be more useful, but it wasn't (not the one in build/ or .android), but as a workaround, some :app module AndroidManifest.xml changes using uses-sdk will work:
<manifest ...>
<uses-sdk android:targetSdkVersion="29" android:minSdkVersion="21"
tools:overrideLibrary="com.example.flutter_module, com.example.flutter_module.host"/>
...
</manifest>
(I set the default package name for the flutter module but you should replace both instances of com.example.flutter_module with your package name. (check your build.gradles). What I do here is raise the minSDK for the 2 flutter modules that were added. The error message you got recommended lowering the minSDK for camera to 16, but this is not a good idea (the camera plugin developers set it to 21 probably because the APIs they use have minSDK 21, e.g. camera2).
How to setup firebase/ dependencies config in build.gradle? (i.e. firebase_ml_vision and firebase 'platform specific configuration'): Change your main app's app/build.gradle and AndroidManifest.xml as per the instructions. This is what the doc says:
Perform those Android Gradle file edits on your outer, existing Android app rather than in your Flutter module.
Let me know if you need anymore help :)

on android/app/build.gradle changing minSdkVersion to 21

Related

How can I add foregroundServiceType to a library manifest while maintaining backwards compatibility?

My library project has a location service, and per Android Q requirements it sets the android:foregroundServiceType="location" attribute in the manifest. When an app module uses my library and compiles against API level 28, it fails with the following error:
AndroidManifest.xml:57: AAPT: error: attribute android:foregroundServiceType not found.
How can my library maintain compatibility with older versions, while making sure the functionality works on Android Q?
I had same error and after migrating to Androidx and updating compileSdkVersion from 28 to 29 my issue was resolved. So please do these changes and you can get your solution
My goal is to avoid breaking anyone's build when the library version is updated, and at the same time avoid forcing the developer to compile against API 29. It seems I have two choices:
Provide a separate library so that developers compiling against API 28 and lower don't get impacted;
warn developers targeting the new version to replace the service definition in the manifest using tools:node="replace".
The problem with the first approach is that I will need to maintain two libraries for some time. The problem with the second is that developers must remember to revert the change once they update the SDK version.
In my case, I will go with the second approach. By passing an explicit foreground service type to the startForeground method when targeting Android Q, I can cause a crash if the type is not set in the manifest. The developer can therefore catch this when targeting Android Q and revert the manifest change to fix it.

android <uses-sdk> does not update

Using Eclipse, I was using android:minSdkVersion="10", got the error message that this was too low, and updated it to 18. After cleaning the project, refreshing and building Android Environment, I still get the same error message!
In Properties -> Android -> Project Build Target, I have selected Android 4.4.2, with an API level of 19.
in AndroidManifest.xml:
<uses-sdk android:minSdkVersion="18" android:targetSdkVersion="19"/>
ERROR:
"Call requires API level 17(current min is10):android.app.AlertDialog.Builder#setOnDismissListener"
How do I make sure my update in AndroidManifest really works?
Thanks in advance.
It has been a while since I've used Eclipse for Android development. If you're new to Android, I'd highly recommend that you check out Android Studio, instead.
Anyway, this sounds like a build issue. I'm imagining that you're using the default ant build script so in that case the most likely culprit is your project properties file.
Look for a file called "project.properties"
and add/modify a line to contain the following:
# Project target
target=android-18
It sounds like it's currently pointing to android-10. You can find more information on this file and others here.

Skipping Android Studio AndroidManifest merging errors due to minSDK and targetSDK version mismatches

Android studio throws build errors when the minSDKVersions of main and library projects do not match, during merging process of AndroidManifest files..
This means I have to revisit the minSDKVersion/targetSDKVersion my app supports and have a unified versions across my project libraries....Is there someway I can force Android studio to skip this version checks during manifest merging?
[Error format]
Main manifest has uses-sdk android:targetSdkVersion=x but library uses targetSdkVersion=y
What went wrong:
Execution failed for task ':app:processDebugManifest'.
Manifest merging failed. See console for more info.
I take it you're having problems with a library having a higher minSdkVersion than the app that includes it? If so, the build breakage is by design -- the intent is that the app developer should be made aware of the problem and consciously do something about it. It would be bad to just silently increase the app's minSdkVersion to match the highest value found in one of the libraries.
There's a discussion at:
https://groups.google.com/forum/#!topic/adt-dev/e656VuS3BtM
Having said that, we're currently working on revamping manifest merging, so it's possible this will change at some point in the future.

Error with admob banners [duplicate]

Eclipse is giving me an error on the android:configChanges line in my AndroidManifest.xml:
<activity android:name="com.google.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"></activity>
the error is:
error: Error: String types not allowed (at 'configChanges' with value 'keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize').
If I leave only keyboard|keyboardHidden|orientation there's no error, but compiler asks for the 4 remaining ones when I try and build.
I'm using GoogleAdMobAdsSDK-4.3.1.
Any ideas?
EDIT: I got it working by changing my project.properties (default.properties on SDK's lower then 14) file to:
# Project target.
target=android-14
and in my SDK Manager having the SDK Platform Android 4.0 - Revision 14 installed.
It should also work for SDK Platform android 3.2 - revision 13, so you just have to change the project.properties target to android-13 if that is the case. Basically you just have to make sure that the SDK revision is 13 or above, and that you have that SDK installed in the SDK manager and the project target in default/project.properties pointing to it.
Easy solution: (and NO you don't need to to change the min-sdk value !!)
Step 1:
Change "project.properties" file
# Project target.
target=android-13
Step 2:
In Eclipse
Project > Clean... > (select your project) > Clean projects selected below > OK
For a complete explanation with real example use this tutorial http://www.monkeycoder.co.nz/Community/posts.php?topic=1121
Cheers !
Simple answer: the mentioned config changes are not support in Android 2.1, have a look here:
http://developer.android.com/guide/topics/manifest/activity-element.html#config
e.g. uiMode needs API Level 8.
From the official AdMob Documentation:
Requirements
The Google AdMob Ads SDK for Android requires Android 1.5 or later. Make sure you have the latest copy of the Android SDK and that you're compiling against at least Android v3.2 (set target in default.properties to android-13).
have a look here: https://developers.google.com/admob/android/quick-start
So I think your tools version is not updated to at least Version 13.
For those using Eclipse there is an easier way:
Right click your project folder in the left "Package Explorer" pane and click Properties -> Android -> and in the "Project Build Target" list check off API 13 or up.
Note: this is the same effect as editing project.properties which is auto-generated anyway.
This will build your project against the Android 3.2 SDK which includes the terms that were previously unrecognized.
You may leave your android:minSdkVersion and targetSdkVersion values the same in your Manifest.xml.
Be warned though, if you don't set your targetSdkVersion to API 12 or lower (or don't set it at all) the Android system will assume that the android:configChanges values screenSize and smallestScreenSize (which were introduced in API 13) are accounted for and thus will be allowed to destroy-restart your activity. If you wanted to avoid this you must include those terms in your other <activity> tags (which probably only had keyboard|keyboardHidden|orientation until now).
However, if your application targets API level 12 or lower, then your activity always handles this configuration change itself (this configuration change does not restart your activity, even when running on an Android 3.2 or higher device).
Quote is from here.
I had the same problem so I came here.
I have downloaded the sample code from https://developers.google.com/admob/android/quick-start, I still had the problem with all answers above so I used the same admob sdk, they offer in the sample project. Redo the build jars thing, changed target to android-15, and used the same line they use:
<activity android:name="com.google.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation"/>
And it works!
Did you use
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|‌​screenSize|smallestScreenSize
or shorter one? If you change your target above 13 and use longer configChanges one (which I wrote), it should work.
Easy solution:
Change "project.properties" file to 21
# Project target.
target=android-21
All new Android apps created after October 14, 2011 will require an AdMob SDK that was released on or after March 15, 2011. This corresponds to version 4.0.2+ for Android. If you downloaded the library from our official download site, then you're already set. Otherwise you may have an old version of the AdMob SDK that was released prior to March 15, 2011, and your new app will not receive any ad impressions until you update your SDK.

Admob Error in Eclipse for android:configChanges

Eclipse is giving me an error on the android:configChanges line in my AndroidManifest.xml:
<activity android:name="com.google.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"></activity>
the error is:
error: Error: String types not allowed (at 'configChanges' with value 'keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize').
If I leave only keyboard|keyboardHidden|orientation there's no error, but compiler asks for the 4 remaining ones when I try and build.
I'm using GoogleAdMobAdsSDK-4.3.1.
Any ideas?
EDIT: I got it working by changing my project.properties (default.properties on SDK's lower then 14) file to:
# Project target.
target=android-14
and in my SDK Manager having the SDK Platform Android 4.0 - Revision 14 installed.
It should also work for SDK Platform android 3.2 - revision 13, so you just have to change the project.properties target to android-13 if that is the case. Basically you just have to make sure that the SDK revision is 13 or above, and that you have that SDK installed in the SDK manager and the project target in default/project.properties pointing to it.
Easy solution: (and NO you don't need to to change the min-sdk value !!)
Step 1:
Change "project.properties" file
# Project target.
target=android-13
Step 2:
In Eclipse
Project > Clean... > (select your project) > Clean projects selected below > OK
For a complete explanation with real example use this tutorial http://www.monkeycoder.co.nz/Community/posts.php?topic=1121
Cheers !
Simple answer: the mentioned config changes are not support in Android 2.1, have a look here:
http://developer.android.com/guide/topics/manifest/activity-element.html#config
e.g. uiMode needs API Level 8.
From the official AdMob Documentation:
Requirements
The Google AdMob Ads SDK for Android requires Android 1.5 or later. Make sure you have the latest copy of the Android SDK and that you're compiling against at least Android v3.2 (set target in default.properties to android-13).
have a look here: https://developers.google.com/admob/android/quick-start
So I think your tools version is not updated to at least Version 13.
For those using Eclipse there is an easier way:
Right click your project folder in the left "Package Explorer" pane and click Properties -> Android -> and in the "Project Build Target" list check off API 13 or up.
Note: this is the same effect as editing project.properties which is auto-generated anyway.
This will build your project against the Android 3.2 SDK which includes the terms that were previously unrecognized.
You may leave your android:minSdkVersion and targetSdkVersion values the same in your Manifest.xml.
Be warned though, if you don't set your targetSdkVersion to API 12 or lower (or don't set it at all) the Android system will assume that the android:configChanges values screenSize and smallestScreenSize (which were introduced in API 13) are accounted for and thus will be allowed to destroy-restart your activity. If you wanted to avoid this you must include those terms in your other <activity> tags (which probably only had keyboard|keyboardHidden|orientation until now).
However, if your application targets API level 12 or lower, then your activity always handles this configuration change itself (this configuration change does not restart your activity, even when running on an Android 3.2 or higher device).
Quote is from here.
I had the same problem so I came here.
I have downloaded the sample code from https://developers.google.com/admob/android/quick-start, I still had the problem with all answers above so I used the same admob sdk, they offer in the sample project. Redo the build jars thing, changed target to android-15, and used the same line they use:
<activity android:name="com.google.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation"/>
And it works!
Did you use
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|‌​screenSize|smallestScreenSize
or shorter one? If you change your target above 13 and use longer configChanges one (which I wrote), it should work.
Easy solution:
Change "project.properties" file to 21
# Project target.
target=android-21
All new Android apps created after October 14, 2011 will require an AdMob SDK that was released on or after March 15, 2011. This corresponds to version 4.0.2+ for Android. If you downloaded the library from our official download site, then you're already set. Otherwise you may have an old version of the AdMob SDK that was released prior to March 15, 2011, and your new app will not receive any ad impressions until you update your SDK.

Categories

Resources