ByneappLLC / flutter_config

Config Variables for your Flutter Apps.
BSD 2-Clause "Simplified" License
148 stars 67 forks source link

Null check operator on Android in Release Mode #37

Open akmjenkins opened 3 years ago

akmjenkins commented 3 years ago

Works fine in debug mode, when I run it in release mode I get this trace from await FlutterConfig.loadEnvVariables()

EDIT: Was originally running v 1.0.8. Upgraded to 2.0.0, issue exists (for me) in both

E/flutter (18251): [ERROR:flutter/lib/ui/ui_dart_state.cc(199)] Unhandled Exception: Null check operator used on a null value
E/flutter (18251): #0      MethodChannel.binaryMessenger (package:flutter/src/services/platform_channel.dart:142)
E/flutter (18251): #1      MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:148)
E/flutter (18251): #2      MethodChannel.invokeMethod (package:flutter/src/services/platform_channel.dart:331)
E/flutter (18251): #3      MethodChannel.invokeMapMethod (package:flutter/src/services/platform_channel.dart:358)
E/flutter (18251): #4      FlutterConfig.loadEnvVariables (package:flutter_config/flutter_config.dart:21)

Mandatory flutter doctor -v

[✓] Flutter (Channel stable, 2.2.0, on macOS 11.3.1 20E241 darwin-x64, locale en-CA)
    • Flutter version 2.2.0 at /Users/adev/dev/flutter
    • Framework revision b22742018b (12 days ago), 2021-05-14 19:12:57 -0700
    • Engine revision a9d88a4d18
    • Dart version 2.13.0

[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
    • Android SDK at /Users/adev/Library/Android/sdk
    • Platform android-30, build-tools 30.0.3
    • Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 11.0.8+10-b944.6916264)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Xcode 12.5, Build version 12E262
    • CocoaPods version 1.10.1

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 4.2)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 11.0.8+10-b944.6916264)

[✓] VS Code (version 1.56.2)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.22.0

[✓] Connected device (2 available)
    • SM P610 (mobile) • R52R305DGZH • android-arm64  • Android 10 (API 29)
    • Chrome (web)     • chrome      • web-javascript • Google Chrome 90.0.4430.212

Also worth pointing out that when I build, I get these gradle warnings - not sure if they are related or not to my issue:

w: Runtime JAR files in the classpath should have the same version. These files were found in the classpath:
    /Users/adev/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib-jdk7/1.4.21/26b6082f9296911bdcb8e72a7cc68692c7025a03/kotlin-stdlib-jdk7-1.4.21.jar (version 1.4)
    /Users/adev/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib/1.4.21/4a668382d7c38688d3490afde93b6a113ed46698/kotlin-stdlib-1.4.21.jar (version 1.4)
    /Users/adev/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib-common/1.4.21/7f48a062aa4b53215998780f7c245a4276828e1d/kotlin-stdlib-common-1.4.21.jar (version 1.4)
    /Users/adev/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-reflect/1.3.0/6fd129fd9ba8581f2cb9c58bfd431dda4ee0457e/kotlin-reflect-1.3.0.jar (version 1.3)
    /Users/adev/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib-jdk7/1.3.70/95aee922bc2a0fff3b7bfa1b6503ff0afe38264a/kotlin-stdlib-jdk7-1.3.70.jar (version 1.3)
    /Users/adev/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib-jdk8/1.4.31/e613be5465ef1e6fd0468707690b7ebf625ea2fe/kotlin-stdlib-jdk8-1.4.31.jar (version 1.4)
    /Users/adev/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib/1.3.70/e5d97e25bb5b30dcfc022ec1c8f3959a875257fb/kotlin-stdlib-1.3.70.jar (version 1.3)
    /Users/adev/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib-jdk7/1.4.31/84ce8e85f6e84270b2b501d44e9f0ba6ff64fa71/kotlin-stdlib-jdk7-1.4.31.jar (version 1.4)
    /Users/adev/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib-common/1.3.50/3d9cd3e1bc7b92e95f43d45be3bfbcf38e36ab87/kotlin-stdlib-common-1.3.50.jar (version 1.3)
    /Users/adev/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib-jdk7/1.3.50/50ad05ea1c2595fb31b800e76db464d08d599af3/kotlin-stdlib-jdk7-1.3.50.jar (version 1.3)
    /Users/adev/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib/1.3.50/b529d1738c7e98bbfa36a4134039528f2ce78ebf/kotlin-stdlib-1.3.50.jar (version 1.3)
    /Users/adev/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib-jdk7/1.3.61/70dffc5f8ac5ea7c34f30deac5b9d8b1d48af066/kotlin-stdlib-jdk7-1.3.61.jar (version 1.3)
    /Users/adev/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib/1.3.61/4702105e97f7396ae41b113fdbdc180ec1eb1e36/kotlin-stdlib-1.3.61.jar (version 1.3)
    /Users/adev/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib-common/1.3.61/65abb71d5afb850b68be03987b08e2c864ca3110/kotlin-stdlib-common-1.3.61.jar (version 1.3)
    /Users/adev/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib/1.4.31/a58e0fb9812a6a93ca24b5da75e4b5a0cb89c957/kotlin-stdlib-1.4.31.jar (version 1.4)
    /Users/adev/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib-common/1.4.31/6dd50665802f54ba9bc3f70ecb20227d1bc81323/kotlin-stdlib-common-1.4.31.jar (version 1.4)
    /Users/adev/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib-common/1.3.70/3fa8dd6c896d635e78201e5e811545f3846dec04/kotlin-stdlib-common-1.3.70.jar (version 1.3)
w: Consider providing an explicit dependency on kotlin-reflect 1.4 to prevent strange errors
w: Some runtime JAR files in the classpath have an incompatible version. Consider removing them from the classpath
edTheGuy00 commented 3 years ago

Hello, if you are using Proguard, you will need to add the rules to avoid the obfuscator from stripping away needed classes. It is mentioned on the Android Setup Guide

akmjenkins commented 3 years ago

@edTheGuy00 thanks for the reply!

On my debugging journey before I posted this issue, I added android/app/proguard-rules.pro to my project with:

-keep class com.myappname.suffix.BuildConfig { *; }

And it did not solve my issue.

edTheGuy00 commented 3 years ago

Just to double check again, You replaced com.myappname.suffix with YOUR app name correct? For example, in my app I would have

-keep class com.byneapp.coolApp.BuildConfig { *; }

Secondly, I'm not 100% sure that is correct, I think you might also need to add the FlutterConfigPlugin class.

-keep class com.byneapp.flutter_config.FlutterConfigPlugin { *; }

Can you check for me? I normally just skip using pro-guard alltogether as I normally have to manually add almost every single Native Class into it, which makes it pretty useless for me and only saves a few KB on APK size.

akmjenkins commented 3 years ago

Just to double check again, You replaced com.myappname.suffix with YOUR app name correct?

Yes.

I've also added:

-keep class com.myappname.flutter_config.FlutterConfigPlugin { *; }

with no luck.

How can I disable proguard? I noticed in my gradle.properties file there's this android.enableR8=true and I was starting to wondering if R8 had anything to do with this?

abdullah432 commented 3 years ago

Same issue, no luck so far

developerjamiu commented 4 months ago

According to the documentation here, if you use applicationIdSuffix i.e. com.yourorg.mobile.suffix that is different from the package name indicated in your AndroidManifest.xml you need to add line in your android/app/build.gradle file.

defaultConfig {
    ...
    resValue "string", "build_config_package", "YOUR_PACKAGE_NAME_IN_ANDROIDMANIFEST.XML"
}