Skip to content

Cannot start FlutterActivity when adding flutterpart library as aar module to existing application #18025

Closed
@tomergoldst

Description

@tomergoldst

Steps to Reproduce

  1. Create new flutter project

  2. Create new Android app

  3. Add flutter project into existing android app (from step 2) according to

  4. run the android app and start the MainActivity of flutter project -> everything works

  5. run gradle -> assemble for the flutter project Build directory

  6. copy the flutterpart-release.aar generated at build/outputs/arr

  7. Create a different new Android app

  8. Create new module ->Import JAR/ARR package -> select flutterpart-release.aar -> finish

  9. add to app build.grade "implementation project(':flutterpart')"

  10. add button to start flutterpart MainAcitivty
    ComponentName componentName = new ComponentName(getBaseContext(),
    "com.example.flutterpart.MainActivity");
    Intent intent = new Intent().setComponent(componentName);
    startActivity(intent);

  11. Run the app -> click the button -> app crashed

Logs

Crash log

05-30 16:32:36.124 21199-21199/com.example.androidwithflutter3 A/flutter: [FATAL:flutter/fml/icu_util.cc(95)] Check failed: context->IsValid(). Must be able to initialize the ICU context. Tried: /data/user/0/com.example.androidwithflutter3/app_flutter/icudtl.dat
05-30 16:32:36.124 21199-21199/com.example.androidwithflutter3 A/libc: Fatal signal 6 (SIGABRT), code -6 in tid 21199 (oidwithflutter3)
Doctor summary (to see all details, run flutter doctor -v):
[√] Flutter (Channel beta, v0.4.4, on Microsoft Windows [Version 10.0.16299.125], locale he-IL)
[√] Android toolchain - develop for Android devices (Android SDK 27.0.3)
[√] Android Studio (version 3.1)
[!] IntelliJ IDEA Community Edition (version 2018.1)
    X Flutter plugin not installed; this adds Flutter specific functionality.
    X Dart plugin not installed; this adds Dart specific functionality.
[√] Connected devices (1 available)

Activity

luoyushouchai

luoyushouchai commented on Jun 6, 2018

@luoyushouchai

For my app, add :
ndk { abiFilters 'armeabi', 'armeabi-v7a', 'arm64-v8a', 'x86' }
App crash and throw the same error!

alexandresoler

alexandresoler commented on Jun 13, 2018

@alexandresoler

Same for me.
Works well when including the flutter project as a module with sources (like https://github.com/flutter/flutter/wiki/Add-Flutter-to-existing-apps)
Doesn't works when exporting the flutter project as an aar and include it on my Android APP as a fat aar. (Must be able to initialize the ICU context...)

added
engineflutter/engine repository. See also e: labels.
a: existing-appsIntegration with existing apps via the add-to-app flow
on Jun 25, 2018
davidbilly

davidbilly commented on Jun 27, 2018

@davidbilly

Same for me, after export to AAR.

App crash and show "A/flutter: [FATAL:flutter/fml/icu_util.cc(95)] Check failed: context->IsValid(). Must be able to initialize the ICU context. Tried: /data/user/0/APP_ID/app_flutter/icudtl.dat"

davidbilly

davidbilly commented on Jun 27, 2018

@davidbilly

Guys, after few attempt and i manage let AAR work with my demo app on simulator.

Reason : The "assets/flutter_shared/icudtl.dat" was not generated when you're export to AAR but export APK does include "icudtl" file if you directly embedded flutter SDK.

How to :
Step :

  1. Build APK with flutter SDK directly. e.g : https://github.com/flutter/flutter/tree/flutter_module/examples/flutter_view
  2. After you successfully build APK and use zip to extract APK and copy out the "icudtl.dat"
  3. create "src/main/assets/flutter_shared/" folders and copy "icudtl.dat" to under "flutter_shared" folder on your library which used to export AAR later.
  4. export your library to AAR and extract it make sure "icudtl.dat" created.
  5. import AAR file into your main project and enjoy it.

Note : i'm not sure that "icudtl.dat" file what for and not sure will be work on all of android devices, please share/contribute me the result as i not own much android devices to test.

Please share if have any better workaround for this issue.

Hopefully, in future flutter dev @mit-mit @mravn-google will included for export AAR.

Sorry for my bad english.

mravn-google

mravn-google commented on Jun 27, 2018

@mravn-google
Contributor

@davidbilly Using the new Flutter module template, the icudtl.dat file is included in the apk of the host app. That file tells Flutter how to do international text processing with unicode.

davidbilly

davidbilly commented on Jun 27, 2018

@davidbilly

@mravn-google

Hi, thanks for quick reply.

For my case, i have to use our company existing native SDK for our customer app and i'm thinking by using flutter framework just for UI part for IOS and android for 1 time development.

But the logic part still on native which we already developed long time ago.

So we have to use AAR to support our customer app. So far seem "flutter_view" and "platform_view" fulfil our requirement.

Also, we don't wish our customer have to setup for flutter env and download flutter source code just because they using our SDK. its too much development cost for them.

So, all the source within AAR will be better, they just need to import our AAR SDK to their project.

Thanks.

This is my env :

[✓] Flutter (Channel master, v0.5.6-pre.82, on Mac OS X 10.12.6 16G29, locale en-SG)
[✓] Android toolchain - develop for Android devices (Android SDK 27.0.3)
[✓] Android Studio (version 3.1)
chaangliu

chaangliu commented on Sep 17, 2018

@chaangliu

@davidbilly Using the new Flutter module template, the icudtl.dat file is included in the apk of the host app. That file tells Flutter how to do international text processing with unicode.

Hi I'm using the new Flutter module template and adding flutter module as source code, but still encountering this issue..

When searching in the project I can see icudtl.dat is already included in the jar. Why can't flutter find it?
img

matthew-carroll

matthew-carroll commented on Sep 18, 2018

@matthew-carroll
Contributor

@tomergoldst I tried to repro your issue but was unable to find any issues. Here are the steps that I took:

  1. Created an Android app project called android_app
  2. Created a Flutter module project called flutter_module
  3. Linked android_app to flutter_module as per the steps in the Wiki
  4. Changed MainActivity in android_app to extend FlutterActivity
  5. Launched android_app and confirmed that the Flutter UI displayed as expected
  6. Changed android_app to an Android library by editing the build.gradle file
  7. Ran ./gradlew assemble to create an AAR
  8. Created a new Android app project called android_app2
  9. Added the earlier AAR as a module to android_app2
  10. Added a button to MainActivity2 within android_app2 that launches MainActivity from within the AAR

The above steps worked as expected without any build errors or crashes.

I'm going to close this ticket. If you still have issues with the above steps then please re-open with any additional information that might help.

comigor

comigor commented on Oct 30, 2018

@comigor
Contributor

@matthew-carroll We've just created a repo to reproduce the issue following your step above (using flutter 40fc45a): https://github.com/Igor1201/min-repro-flutter

Your steps actually were missing the import of flutter classes themselves (the .aar generated from the .android/Flutter project) that is not embedded on the MyApplication project (the one you converted from an app to a library).

So our steps actually were:

  1. Created an Android app project called app (on android folder)
  2. Created a Flutter module project called flutter_module (on root)
  3. Linked app to flutter_module as per the steps in the Wiki
  4. Changed MainActivity in app to extend FlutterActivity
  5. Launched app and confirmed that the Flutter UI displayed as expected
  6. Changed app to an Android library by editing the build.gradle file
  7. Ran ./gradlew assemble to create an AAR
  8. Created a new Android app project called app (on android_app_2 folder)
  9. Added the earlier AAR as a module to android_app_2
  10. Ran ./gradlew flutter:assemble on android folder
  11. Added the flutter AAR (flutter_module/.android/Flutter/(...)/outputs/flutter-debug.aar) as a module to android_app_2
  12. Added a button to MainActivity2 within android_app_2 that launches MainActivity from within the app AAR
  13. Crashed with the missing icudtl.dat error

We thought about some solutions to this problem:

  1. Change flutter.jar to be flutter.aar
    By definition, jar files on android shouldn't contain assets, so migrating flutter to an AAR would make it work, as the compiler would than merge the assets.

  2. Add an assets folder containing flutter_shared to the generated .android/Flutter module
    This way, the output of this project (which is an AAR) will contain the flutter_shared folder inside assets, which will be merged to the final APK.

What do you think about the solutions? Do you have anything in mind, or do you have any concern with any of these approaches?

graydalf

graydalf commented on Nov 2, 2018

@graydalf

@tomergoldst I tried to repro your issue but was unable to find any issues. Here are the steps that I took:

  1. Created an Android app project called android_app
  2. Created a Flutter module project called flutter_module
  3. Linked android_app to flutter_module as per the steps in the Wiki
  4. Changed MainActivity in android_app to extend FlutterActivity
  5. Launched android_app and confirmed that the Flutter UI displayed as expected
  6. Changed android_app to an Android library by editing the build.gradle file
  7. Ran ./gradlew assemble to create an AAR
  8. Created a new Android app project called android_app2
  9. Added the earlier AAR as a module to android_app2
  10. Added a button to MainActivity2 within android_app2 that launches MainActivity from within the AAR

The above steps worked as expected without any build errors or crashes.

I'm going to close this ticket. If you still have issues with the above steps then please re-open with any additional information that might help.

Hi, I need your help.
Can you show me the build.gradle of your sixth step? please.

32 remaining items

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    a: existing-appsIntegration with existing apps via the add-to-app flowengineflutter/engine repository. See also e: labels.t: gradle"flutter build" and "flutter run" on AndroidtoolAffects the "flutter" command-line tool. See also t: labels.waiting for customer responseThe Flutter team cannot make further progress on this issue until the original reporter responds

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @xster@zoechi@comigor@kimlet@kf6gpe

        Issue actions

          Cannot start FlutterActivity when adding flutterpart library as aar module to existing application · Issue #18025 · flutter/flutter