flutter_blue is not working in release apk (Flutter) - flutter

While debugging the app Bluetooth is scanning and identifying near by devices. In release mode, it's not working.

Add the following code in [Project-Name]/android/app/build.gradle
buildTypes {
release {
signingConfig signingConfigs.release
shrinkResources false // this line
minifyEnabled false // this line
}
}

Related

Flutter webrtc not working properly in release mode

I am using WebRTC for video conference within my flutter app.
The app works as expected in debug mode. I am able to establish the connection and the video from both ends is visible without any issues.
However, when I build an apk and test it on real devices, video conferencing fails. Video from both devices is not showing up on the screen. It is only a white screen with no videos where there should be 2 videos.
Here's the code I am referring to: https://github.com/md-weber/webrtc_tutorial
Thanks.
What I have learnt is WebRTC is not really a production ready solution. One still needs to setup STUN/TURN server as discussed here - https://github.com/flutter-webrtc/flutter-webrtc-server/issues/30
If one is excited to explore in future, they can refer to -
https://meetrix.io/blog/webrtc/coturn/installation.html
https://medium.com/av-transcode/what-is-webrtc-and-how-to-setup-stun-turn-server-for-webrtc-communication-63314728b9d0
I do not have the time or energy to spend on this now, but will surely be back when we have a bigger team. For now I am going to use on of the readymade solutions in the market.
When you compile the release apk, you need to add the following operations,
1-Edit /android/app/build.gradle
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
minifyEnabled true
useProguard true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
2-And create new file /android/app/proguard-rules.pro
## Flutter wrapper
-keep class io.flutter.app.** { *; }
-keep class io.flutter.plugin.** { *; }
-keep class io.flutter.util.** { *; }
-keep class io.flutter.view.** { *; }
-keep class io.flutter.** { *; }
-keep class io.flutter.plugins.** { *; }
-dontwarn io.flutter.embedding.**
## Flutter WebRTC
-keep class com.cloudwebrtc.webrtc.** { *; }
-keep class org.webrtc.** { *; }
refer to [https://flutter-webrtc.org/docs/flutter-webrtc/get-stared#important-reminder][1]

Flutter SDK not found in Android Studio + MacOS

Whenever i try to run my flutter app on Android Studio, this error message pop up:
FAILURE: Build failed with an exception.
* Where:
Build file '/Users/max/Projects/Flutter/myapp/android/app/build.gradle' line: 11
* What went wrong:
A problem occurred evaluating project ':app'.
> Flutter SDK not found. Define location with flutter.sdk in the local.properties file.
these are the first lines of said build.gradle file
def localProperties = new Properties()
def localPropertiesFile = rootProject.file('key.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.")
}
I got it working on XCode.
The real problem is that i have installed flutter in that very folder, and i have 0 issue when i run flutter doctor -v.
After some googling i have found some answers but they were not useful because all of them had me verify
A - the flutter SDK path as per following image:
B - my myapp/android/local.properties file, which is as follows
sdk.dir=/Users/max/Library/Android/sdk
flutter.sdk=/Users/max/SDKs/flutter
flutter.buildMode=debug
flutter.versionName=1.0.0
flutter.versionCode=1
C - my modules dependency
does anyone know what is going on? it's been 2 weeks and i haven't figured this out yet.
thanks in advance.

ionic cordova local notifications sounds not working

I'm trying to build my ionic mobile app with local notifications and I want to include sound in the notification. I already tried adding a sound file to the resources folder and add the below code. But still not working.
recurringMonthAlarm(alarmdata,eleindex){
this.localNotifications.schedule({
id: eleindex,
title: alarmdata.title,
text: alarmdata.desc,
sound: this.setSound(),
foreground: true,
trigger: {firstAt: alarmdata.startTime,
every: ELocalNotificationTriggerUnit.MONTH
}
});
}
setSound() {
return 'file://audio/alarmsound.wav';
}
Looks like your File Path Issue, Add your sound file in your assets folder.
Try:
setSound() {
if (this.platform.is('android')) {
return 'file://assets/sounds/shame.mp3' // for Android
} else {
return 'file://assets/sounds/bell.mp3' // for iOS
}
}

Does not allow to save image to local directory in flutter in android 10

I'm trying to save an image to phone local directory. Here I use image_downloader package for that. Here's my code
class DownloadImage {
Future writeToDownloadPath(GridImage imageData) async {
try {
var imageId = await ImageDownloader.downloadImage(imageData.url
,destination: AndroidDestinationType.custom(directory: 'motivational Quotes',
inPublicDir: true ,subDirectory: '/motivational Quotes${imageData.location}'));
print('imageId' + imageId.toString());
if (imageId == null) {
return;
}
} catch(e) {
print(e.toString());
}
}
}
When I run on Android 10 device and try to download an image it gives me this error,
E/MethodChannel#plugins.ko2ic.com/image_downloader(25282): java.lang.IllegalStateException: Not one of standard directories: motivational Quotes
I already added android:requestLegacyExternalStorage="true" in AndroidManifest and set targetSdkVersion and compileSdkVersion to 29 in build.gradle file. I did flutter clean and run the code but issue remain the same.
build.gradle
defaultConfig {
applicationId "com.example.app
minSdkVersion 21
targetSdkVersion 29
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
multiDexEnabled true
}
AndroidManifest
<application
android:name="io.flutter.app.FlutterApplication"
android:label="Motivational Quotes"
android:icon="#mipmap/ic_launcher"
android:requestLegacyExternalStorage="true">
I would be really grateful if anyone can help me with this issue. Thanks !
I faced the same issue with Android 10, I think the feature of saving in custom directory is not compatible with Android10 . The same code works perfectly for others
There are only 4 standard directories in this package.
/// Environment.DIRECTORY_DOWNLOADS
static final directoryDownloads =
AndroidDestinationType._internal("DIRECTORY_DOWNLOADS");
/// Environment.DIRECTORY_PICTURES
static final directoryPictures =
AndroidDestinationType._internal("DIRECTORY_PICTURES");
/// Environment.DIRECTORY_DCIM
static final directoryDCIM =
AndroidDestinationType._internal("DIRECTORY_DCIM");
/// Environment.DIRECTORY_MOVIES
static final directoryMovies =
AndroidDestinationType._internal("DIRECTORY_MOVIES");
So, you have to change here:
var imageId = await ImageDownloader.downloadImage(imageData.url
,destination: AndroidDestinationType.custom(directory: 'motivational Quotes',
inPublicDir: true ,subDirectory: '/motivational Quotes${imageData.location}'));
I advise you to keep it simple like this:
destination: AndroidDestinationType.directoryPictures
..inExternalFilesDir()
..subDirectory('${imageData.location}'),

Flutter Square Plugin crashes in release only

Flutter Square plugin crashes only in release when I use invalid card or press back.
But when I use flutter run --release & hook up my mobile. the crashes don't occur & the app works perfectly!
here's the code we used
void _pay() async {
await InAppPayments.setSquareApplicationId(sqAppId);
try {
await InAppPayments.startCardEntryFlowWithBuyerVerification(
money: Money((money) => money
..amount = 0
..currencyCode = 'USD'),
collectPostalCode: true,
contact: Contact((ContactBuilder contact) {
return contact.givenName = username;
}),
buyerAction: "Store",
squareLocationId: sqLocationId,
onBuyerVerificationSuccess: (BuyerVerificationDetails result) {
addCard(result.nonce, result.card.postalCode);
},
onBuyerVerificationFailure: (err) {
return showErrorDialog(context, err.toString());
},
onCardEntryCancel: () {});
} on Exception catch (e) {
print(e);
}
}
What is the difference between flutter build & flutter run --release ?
Could I use the APK out from flutter run & upload it to google play ?
In the release version you have to add the PERMISSIONS explicitly.
Try adding android.permission.INTERNET to the Manifest file.
Add
<uses-permission android:name="android.permission.INTERNET"/>
to the AndroidManifest.xml located in android/app/src/main.
For your question about uploading a debuggable apk, Google Play-Upload will reject your file.
Refer to this link for the differences between release and debug.