Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missing Plugins exception when adding AAR to existing Android project #23944

Closed
MichaelShnaider opened this issue Nov 5, 2018 · 44 comments
Closed
Labels
a: existing-apps Integration with existing apps via the add-to-app flow c: crash Stack traces logged to the console platform-android Android applications specifically t: gradle "flutter build" and "flutter run" on Android tool Affects the "flutter" command-line tool. See also t: labels.

Comments

@MichaelShnaider
Copy link

MichaelShnaider commented Nov 5, 2018

Steps to Reproduce

  1. Create a new flutter module with "flutter create -t module module_name"
  2. Add a plugin to the module, I added path_provider, but any plugin will cause an error
  3. Add icudtl manually to ./.android/Flutter/app/src/main/assets/flutter_shared/(icu_file_here)
  4. Create an AAR file by going into .android folder and running "./gradlew flutter:assembleDebug"
  5. Take the AAR from the ./android/Flutter/build/outpurs/aar/flutter-debug.aar and add it to my existing android project.
  6. Add the code to launch the flutter view from here: https://github.com/flutter/flutter/wiki/Add-Flutter-to-existing-apps
  7. Run app and see crash.

Error from android Logcat:
Look at the bolded parts of the error

11-05 09:07:21.741 17027-17027/com.example.flutterintegration E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.example.flutterintegration, PID: 17027
    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.flutterintegration/com.example.flutterintegration.MainActivity}: java.lang.RuntimeException: Failed to call observer method
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2913)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3048)
        at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
        at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1808)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loop(Looper.java:193)
        at android.app.ActivityThread.main(ActivityThread.java:6669)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
     Caused by: java.lang.RuntimeException: Failed to call observer method
        at android.arch.lifecycle.ClassesInfoCache$MethodReference.invokeCallback(ClassesInfoCache.java:225)
        at android.arch.lifecycle.ClassesInfoCache$CallbackInfo.invokeMethodsForEvent(ClassesInfoCache.java:193)
        at android.arch.lifecycle.ClassesInfoCache$CallbackInfo.invokeCallbacks(ClassesInfoCache.java:184)
        at android.arch.lifecycle.ReflectiveGenericLifecycleObserver.onStateChanged(ReflectiveGenericLifecycleObserver.java:36)
        at android.arch.lifecycle.LifecycleRegistry$ObserverWithState.dispatchEvent(LifecycleRegistry.java:354)
        at android.arch.lifecycle.LifecycleRegistry.forwardPass(LifecycleRegistry.java:292)
        at android.arch.lifecycle.LifecycleRegistry.sync(LifecycleRegistry.java:332)
        at android.arch.lifecycle.LifecycleRegistry.moveToState(LifecycleRegistry.java:137)
        at android.arch.lifecycle.LifecycleRegistry.handleLifecycleEvent(LifecycleRegistry.java:123)
        at android.arch.lifecycle.ReportFragment.dispatch(ReportFragment.java:121)
        at android.arch.lifecycle.ReportFragment.onActivityCreated(ReportFragment.java:74)
        at android.app.Fragment.performActivityCreated(Fragment.java:2531)
        at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1318)
        at android.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManager.java:1576)
        at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1637)
        at android.app.FragmentManagerImpl.dispatchMoveToState(FragmentManager.java:3046)
        at android.app.FragmentManagerImpl.dispatchActivityCreated(FragmentManager.java:2998)
        at android.app.FragmentController.dispatchActivityCreated(FragmentController.java:182)
        at android.app.Activity.performCreate(Activity.java:7143)
        at android.app.Activity.performCreate(Activity.java:7127)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1271)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2893)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3048) 
        at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78) 
        at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108) 
        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1808) 
        at android.os.Handler.dispatchMessage(Handler.java:106) 
        at android.os.Looper.loop(Looper.java:193) 
        at android.app.ActivityThread.main(ActivityThread.java:6669) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858) 
     **Caused by: java.lang.NoClassDefFoundError: Failed resolution of: Lio/flutter/plugins/pathprovider/PathProviderPlugin;
        at io.flutter.plugins.GeneratedPluginRegistrant.registerWith(GeneratedPluginRegistrant.java:14)
        at io.flutter.facade.Flutter$2.onCreate(Flutter.java:98)
        at java.lang.reflect.Method.invoke(Native Method)
        at** android.arch.lifecycle.ClassesInfoCache$MethodReference.invokeCallback(ClassesInfoCache.java:215)
        at android.arch.lifecycle.ClassesInfoCache$CallbackInfo.invokeMethodsForEvent(ClassesInfoCache.java:193) 
        at android.arch.lifecycle.ClassesInfoCache$CallbackInfo.invokeCallbacks(ClassesInfoCache.java:184) 
        at android.arch.lifecycle.ReflectiveGenericLifecycleObserver.onStateChanged(ReflectiveGenericLifecycleObserver.java:36) 
        at android.arch.lifecycle.LifecycleRegistry$ObserverWithState.dispatchEvent(LifecycleRegistry.java:354) 
        at android.arch.lifecycle.LifecycleRegistry.forwardPass(LifecycleRegistry.java:292) 
        at android.arch.lifecycle.LifecycleRegistry.sync(LifecycleRegistry.java:332) 
        at android.arch.lifecycle.LifecycleRegistry.moveToState(LifecycleRegistry.java:137) 
        at android.arch.lifecycle.LifecycleRegistry.handleLifecycleEvent(LifecycleRegistry.java:123) 
        at android.arch.lifecycle.ReportFragment.dispatch(ReportFragment.java:121) 
        at android.arch.lifecycle.ReportFragment.onActivityCreated(ReportFragment.java:74) 
        at android.app.Fragment.performActivityCreated(Fragment.java:2531) 
        at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1318) 
        at android.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManager.java:1576) 
        at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1637) 
        at android.app.FragmentManagerImpl.dispatchMoveToState(FragmentManager.java:3046) 
        at android.app.FragmentManagerImpl.dispatchActivityCreated(FragmentManager.java:2998) 
        at android.app.FragmentController.dispatchActivityCreated(FragmentController.java:182) 
        at android.app.Activity.performCreate(Activity.java:7143) 
        at android.app.Activity.performCreate(Activity.java:7127) 
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1271) 
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2893) 
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3048) 
        at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78) 
        at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108) 
        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1808) 
        at android.os.Handler.dispatchMessage(Handler.java:106) 
        at android.os.Looper.loop(Looper.java:193) 
        at android.app.ActivityThread.main(ActivityThread.java:6669) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858) 
11-05 09:07:21.744 17027-17027/com.example.flutterintegration E/AndroidRuntime: Caused by: **java.lang.ClassNotFoundException: Didn't find class "io.flutter.plugins.pathprovider.PathProviderPlugin" on path: DexPathList[[zip file "/data/app/com.example.flutterintegration-missTCydw8mkjAJMIMCmpA==/base.apk",** zip file "/data/app/com.example.flutterintegration-missTCydw8mkjAJMIMCmpA==/split_lib_dependencies_apk.apk", zip file "/data/app/com.example.flutterintegration-missTCydw8mkjAJMIMCmpA==/split_lib_resources_apk.apk", zip file "/data/app/com.example.flutterintegration-missTCydw8mkjAJMIMCmpA==/split_lib_slice_0_apk.apk", zip file "/data/app/com.example.flutterintegration-missTCydw8mkjAJMIMCmpA==/split_lib_slice_1_apk.apk", zip file "/data/app/com.example.flutterintegration-missTCydw8mkjAJMIMCmpA==/split_lib_slice_2_apk.apk", zip file "/data/app/com.example.flutterintegration-missTCydw8mkjAJMIMCmpA==/split_lib_slice_3_apk.apk", zip file "/data/app/com.example.flutterintegration-missTCydw8mkjAJMIMCmpA==/split_lib_slice_4_apk.apk", zip file "/data/app/com.example.flutterintegration-missTCydw8mkjAJMIMCmpA==/split_lib_slice_5_apk.apk", zip file "/data/app/com.example.flutterintegration-missTCydw8mkjAJMIMCmpA==/split_lib_slice_6_apk.apk", zip file "/data/app/com.example.flutterintegration-missTCydw8mkjAJMIMCmpA==/split_lib_slice_7_apk.apk", zip file "/data/app/com.example.flutterintegration-missTCydw8mkjAJMIMCmpA==/split_lib_slice_8_apk.apk", zip file "/data/app/com.example.flutterintegration-missTCydw8mkjAJMIMCmpA==/split_lib_slice_9_apk.apk"],nativeLibraryDirectories=[/data/app/com.example.flutterintegration-missTCydw8mkjAJMIMCmpA==/lib/x86, /data/app/com.example.flutterintegration-missTCydw8mkjAJMIMCmpA==/base.apk!/lib/x86, /data/app/com.example.flutterintegration-missTCydw8mkjAJMIMCmpA==/split_lib_dependencies_apk.apk!/lib/x86, /data/app/com.example.flutterintegration-missTCydw8mkjAJMIMCmpA==/split_lib_resources_apk.apk!/lib/x86, /data/app/com.example.flutterintegration-missTCydw8mkjAJMIMCmpA==/split_lib_slice_0_apk.apk!/lib/x86, /data/app/com.example.flutterintegration-missTCydw8mkjAJMIMCmpA==/split_lib_slice_1_apk.apk!/lib/x86, /data/app/com.example.flutterintegration-missTCydw8mkjAJMIMCmpA==/split_lib_slice_2_apk.apk!/lib/x86, /data/app/com.example.flutterintegration-missTCydw8mkjAJMIMCmpA==/split_lib_slice_3_apk.apk!/lib/x86, /data/app/com.example.flutterintegration-missTCydw8mkjAJMIMCmpA==/split_lib_slice_4_apk.apk!/lib/x86, /data/app/com.example.flutterintegration-missTCydw8mkjAJMIMCmpA==/split_lib_slice_5_apk.apk!/lib/x86, /data/app/com.example.flutterintegration-missTCydw8mkjAJMIMCmpA==/split_lib_slice_6_apk.apk!/lib/x86, /data/app/com.example.flutterintegration-missTCydw8mkjAJMIMCmpA==/split_lib_slice_7_apk.apk!/lib/x86, /data/app/com.example.flutterintegration-missTCydw8mkjAJMIMCmpA==/split_lib_slice_8_apk.apk!/lib/x86, /data/app/com.example.flutterintegration-missTCydw8mkjAJMIMCmpA==/split_lib_slice_9_apk.apk!/lib/x86, /system/lib]]
        at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:134)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
        	... 36 more
    	Suppressed: java.io.IOException: No original dex files found for dex location /data/app/com.example.flutterintegration-missTCydw8mkjAJMIMCmpA==/split_lib_resources_apk.apk
        at dalvik.system.DexFile.openDexFileNative(Native Method)
        at dalvik.system.DexFile.openDexFile(DexFile.java:354)
        at dalvik.system.DexFile.<init>(DexFile.java:101)
        at dalvik.system.DexFile.<init>(DexFile.java:75)
        at dalvik.system.DexPathList.loadDexFile(DexPathList.java:394)
        at dalvik.system.DexPathList.makeDexElements(DexPathList.java:354)
        at dalvik.system.DexPathList.<init>(DexPathList.java:164)
        at dalvik.system.BaseDexClassLoader.<init>(BaseDexClassLoader.java:74)
        at dalvik.system.BaseDexClassLoader.<init>(BaseDexClassLoader.java:65)
        at dalvik.system.PathClassLoader.<init>(PathClassLoader.java:64)
        at com.android.internal.os.ClassLoaderFactory.createClassLoader(ClassLoaderFactory.java:73)
        at com.android.internal.os.ClassLoaderFactory.createClassLoader(ClassLoaderFactory.java:88)
        at android.app.ApplicationLoaders.getClassLoader(ApplicationLoaders.java:74)
        at android.app.ApplicationLoaders.getClassLoader(ApplicationLoaders.java:40)
        at android.app.LoadedApk.createOrUpdateClassLoaderLocked(LoadedApk.java:727)
        at android.app.LoadedApk.getClassLoader(LoadedApk.java:810)
        at android.app.LoadedApk.getResources(LoadedApk.java:1032)
        at android.app.ContextImpl.createAppContext(ContextImpl.java:2345)
        at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5749)
        at android.app.ActivityThread.access$1100(ActivityThread.java:199)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1650)
        		... 6 more
@filipproch
Copy link

I think the problem is that the Flutter gradle module, needs to generate a "FAT" AAR package, with all libraries/dependencies included.

@jrmarkham
Copy link

I am experiencing the same issue with a new channel I am creating myself. I am using Kotlin for my build, by the way.

@filipproch
Copy link

I see the problem is, that either you want FAT AAR as I mentioned, or you need to use the part of include_flutter.groovy, which handles including plugins (as subprojects for gradle)

@jrmarkham
Copy link

ok I see -- thanks.

@zoechi zoechi added c: crash Stack traces logged to the console platform-android Android applications specifically t: gradle "flutter build" and "flutter run" on Android a: existing-apps Integration with existing apps via the add-to-app flow labels Nov 7, 2018
@zoechi zoechi added this to the Goals milestone Nov 7, 2018
@zoechi
Copy link
Contributor

zoechi commented Nov 7, 2018

Please add the output of flutter doctor -v.

@MichaelShnaider
Copy link
Author

MichaelShnaider commented Nov 7, 2018

I've updated the Flutter SDK since, but the issue should still be there. Also I have 1 license issue, but this should not be the reason for the error.

i'm on the master branch:

[✓] Flutter (Channel master, v0.10.3-pre.126, on Mac OS X 10.13.6 17G65, locale en-CA)
    • Flutter version 0.10.3-pre.126 at /Users/workspace/flutter
    • Framework revision 1594931605 (4 hours ago), 2018-11-07 07:05:19 -0500
    • Engine revision e64af7510e
    • Dart version 2.1.0 (build 2.1.0-dev.8.0 bf26f760b1)

[!] Android toolchain - develop for Android devices (Android SDK 28.0.3)
    • Android SDK at /Users/Library/Android/sdk
    • Android NDK location not configured (optional; useful for native profiling support)
    • Platform android-28, build-tools 28.0.3
    • Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1024-b01)
    ✗ Android license status unknown.

[✓] iOS toolchain - develop for iOS devices (Xcode 9.4.1)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Xcode 9.4.1, Build version 9F2000
    • ios-deploy 2.0.0
    • CocoaPods version 1.5.3

[✓] Android Studio (version 3.1)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin version 28.0.1
    • Dart plugin version 173.4700
    • Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1024-b01)

[✓] Connected device (3 available)
    • Android SDK built for x86 • emulator-5554                        • android-x86 • Android 9 (API 28) (emulator)

! Doctor found issues in 1 category.

@comigor
Copy link
Contributor

comigor commented Nov 7, 2018

Yeah, that is almost the same problem as #18025, and we've "solved" it by generating a FatAAR (using https://github.com/Mobbeel/fataar-gradle-plugin).

@MichaelShnaider
Copy link
Author

MichaelShnaider commented Nov 8, 2018

@Igor1201 Thanks, for the advice, I tried following the instructions on the Mobbeel page and had trouble generating the far aar file. Instead of generating a 17mb flutter-debug.aar like normal, it is generating a 345 byte ARR, and when I see what is inside it is only a lib/ folder, so im probably just doing something wrong.

Here is what I did:

  1. I opened my flutter project and added a plugin, path_provider.
  2. I added the maven url and the mobbeel plugin classpath under my dependencies, in my ./android/build.gradle.
  3. Then in my ./android/Flutter/build.gradle I added apply plugin: "com.mobbeel.plugin" at the very top and aarPlugin, includeAllInnerDependencies true.
  4. Then when I run the ./gradlew flutter:assembleDebug in my ./android folder, it generates a 345 byte aar.

Clearly, in these steps I skipped the third step of the docs which is to: Mark with 'api' configuration dependecies that need embed on the final AAR. Thus, my best guess is that it doesn't work because I skipped this step. I tried adding a few things like api project(":path_provider") but it doesn't seem to work. I'm just not sure what to put there, and I would greatly appreciate any assistance.

@comigor
Copy link
Contributor

comigor commented Nov 8, 2018

@MichaelShnaider Yeah, the third step is needed, I'm using exactly the configuration you said:

api project(':flutter')
api project(':path_provider')

Also, don't forget to enable the following configuration:

aarPlugin {
    includeAllInnerDependencies true  // It's false for default
}

@MichaelShnaider
Copy link
Author

MichaelShnaider commented Nov 8, 2018

@Igor1201 I tried adding the "api project" lines that you recommended, but I get the error:

FAILURE: Build failed with an exception.

* What went wrong:
Circular dependency between the following tasks:
:flutter:generateDebugRFile
\--- :flutter:generateDebugRFile (*)

(*) - details omitted (listed previously)


* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 1s

I'm not sure where the issue lies, but here is my ./android/build.gradle:

// Generated file. Do not edit.

buildscript {
    repositories {    
            google()
            jcenter()
            maven { url "https://plugins.gradle.org/m2/" }
            
        }

    dependencies {
        classpath 'com.android.tools.build:gradle:3.2.1'
        // Mobbeel to generate the fat aar.
        classpath "com.mobbeel.plugin:fat-aar:2.0.1"
        
    }
}

allprojects {
    repositories {
        google()
        jcenter()
        maven { url "https://plugins.gradle.org/m2/" }
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}`

Here is my ./android/Flutter/build.gradle

// Generated file. Do not edit.
apply plugin: "com.mobbeel.plugin"

def localProperties = new Properties()
def localPropertiesFile = new File(buildscript.sourceFile.parentFile.parentFile, 'local.properties')
if (localPropertiesFile.exists()) {
    localPropertiesFile.withReader('UTF-8') { reader ->
        localProperties.load(reader)
    }
}

def flutterRoot = localProperties.getProperty('flutter.sdk')
if (flutterRoot == null) {
    throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
}

def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
if (flutterVersionCode == null) {
    flutterVersionCode = '1'
}

def flutterVersionName = localProperties.getProperty('flutter.versionName')
if (flutterVersionName == null) {
    flutterVersionName = '1.0'
}


apply plugin: 'com.android.library'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"

android {
    compileSdkVersion 27
    

    defaultConfig {
        minSdkVersion 16
        targetSdkVersion 27
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }

    aarPlugin {
        includeAllInnerDependencies true  // It's false for default
    }


}


flutter {
    source '../..'
}

dependencies {
    testImplementation 'junit:junit:4.12'
    implementation 'com.android.support:support-v13:27.1.1'
    implementation 'com.android.support:support-annotations:27.1.1'
    api project(':flutter')
    api project(':path_provider') 
}

It's possible I added the "api project" lines in the wrong location or something

@comigor
Copy link
Contributor

comigor commented Nov 8, 2018

I see. It seems you are editing the generated flutter project directly, am I right?

In my setup, we have an Android project with two modules (lib and sample) on android folder and the generated lib project on flutter_dart/.android/Flutter (which imports path_provider module as well). In the end, when opening Android Studio we have four modules:

:flutter
:path_provider
:lib
:sample

sample is an android-app module which imports lib.
lib is an android-library module which imports flutter and path_provider, has custom Activity classes and another native plugins we use. We generate a fat-aar from this guy.


Project tree:

➜ tree -L 2 -a
.
├── .circleci
├── .git
├── .gitignore
├── README.md
├── android
│   ├── app
│   ├── lib
│   ├── build
│   ├── build.gradle
│   ├── gradle
│   ├── gradle.properties
│   ├── gradlew
│   ├── gradlew.bat
│   └── settings.gradle
└── flutter_dart
    ├── .android
    │   ├── Flutter
    │   ├── app
    │   ├── build.gradle
    │   ├── gradle
    │   ├── gradle.properties
    │   ├── gradlew
    │   ├── gradlew.bat
    │   ├── include_flutter.groovy
    │   ├── local.properties
    │   └── settings.gradle
    ├── .flutter-plugins
    ├── .gitignore
    ├── .ios
    ├── .metadata
    ├── .packages
    ├── README.md
    ├── analysis_options.yaml
    ├── assets
    ├── flutter_dart.iml
    ├── flutter_dart_android.iml
    ├── build
    ├── fonts
    ├── lib
    ├── pubspec.lock
    ├── pubspec.yaml
    └── test

(I've omitted iOS folder)

@MichaelShnaider
Copy link
Author

MichaelShnaider commented Nov 13, 2018

@Igor1201 Well Igor, first off I appreciate your help so much! I was trying to have it work just by adding and configuring the default AAR generated with "./gradlew flutter:assembleDebug" generated aar, but sadly no success :(

And yea, I was using gradle files from the flutter project, lol, woopsies...

Ok, so NOW I'm trying it your way with the android-library, and generating a Fat AAR from that, so I have a question.

Do you have an activity inside the sample android project which does, the
Flutter.createView(...)
OR
do you do the Flutter.createView(...) inside the the android-libary aka your lib project.

If you have an activity inside the android-library which does Flutter.createView(...) or whatever, if that's the case then, I end up with this error: (saying it can't find flutter essentially)

11-13 13:12:15.937 5538-5538/com.example E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.example, PID: 5538
    java.lang.NoClassDefFoundError: Failed resolution of: Lio/flutter/facade/Flutter;
        at com.example.flutter_wrapper_module.FlutterViewActivity.onCreate(FlutterViewActivity.java:16)
        at android.app.Activity.performCreate(Activity.java:7136)
        at android.app.Activity.performCreate(Activity.java:7127)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1271)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2893)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3048)
        at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
        at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1808)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loop(Looper.java:193)
        at android.app.ActivityThread.main(ActivityThread.java:6669)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
     Caused by: java.lang.ClassNotFoundException: Didn't find class "io.flutter.facade.Flutter" on path: DexPathList[[zip file "/data/app/com.example. -UG0Xr6gPNz4B07ONpyyWpw==/base.apk", zip file "/data/app/com.example. -UG0Xr6gPNz4B07ONpyyWpw==/split_lib_dependencies_apk.apk", zip file "/data/app/com.example. -UG0Xr6gPNz4B07ONpyyWpw==/split_lib_resources_apk.apk", zip file "/data/app/com.example. -UG0Xr6gPNz4B07ONpyyWpw==/split_lib_slice_0_apk.apk", zip file "/data/app/com.example. -UG0Xr6gPNz4B07ONpyyWpw==/split_lib_slice_1_apk.apk", zip file "/data/app/com.example. -UG0Xr6gPNz4B07ONpyyWpw==/split_lib_slice_2_apk.apk", zip file "/data/app/com.example. -UG0Xr6gPNz4B07ONpyyWpw==/split_lib_slice_3_apk.apk", zip file "/data/app/com.example. -UG0Xr6gPNz4B07ONpyyWpw==/split_lib_slice_4_apk.apk", zip file "/data/app/com.example. -UG0Xr6gPNz4B07ONpyyWpw==/split_lib_slice_5_apk.apk", zip file "/data/app/com.example. -UG0Xr6gPNz4B07ONpyyWpw==/split_lib_slice_6_apk.apk", zip file "/data/app/com.example. -UG0Xr6gPNz4B07ONpyyWpw==/split_lib_slice_7_apk.apk", zip file "/data/app/com.example. -UG0Xr6gPNz4B07ONpyyWpw==/split_lib_slice_8_apk.apk", zip file "/data/app/com.example. -UG0Xr6gPNz4B07ONpyyWpw==/split_lib_slice_9_apk.apk"],nativeLibraryDirectories=[/data/app/com.example. -UG0Xr6gPNz4B07ONpyyWpw==/lib/x86, /data/app/com.example. -UG0Xr6gPNz4B07ONpyyWpw==/base.apk!/lib/x86, /data/app/com.example. -UG0Xr6gPNz4B07ONpyyWpw==/split_lib_dependencies_apk.apk!/lib/x86, /data/app/com.example. -UG0Xr6gPNz4B07ONpyyWpw==/split_lib_resources_apk.apk!/lib/x86, /data/app/com.example. -UG0Xr6gPNz4B07ONpyyWpw==/split_lib_slice_0_apk.apk!/lib/x86, /data/app/com.example. -UG0Xr6gPNz4B07ONpyyWpw==/split_lib_slice_1_apk.apk!/lib/x86, /data/app/com.example. -UG0Xr6gPNz4B07ONpyyWpw==/split_lib_slice_2_apk.apk!/lib/x86, /data/app/com.example. -UG0Xr6gPNz4B07ONpyyWpw==/split_lib_slice_3_apk.apk!/lib/x86, /data/app/com.example. -UG0Xr6gPNz4B07ONpyyWpw==/split_lib_slice_4_apk.apk!/lib/x86, /data/app/com.example. -UG0Xr6gPNz4B07ONpyyWpw==/split_lib_slice_5_apk.apk!/lib/x86, /data/app/com.example. -UG0Xr6gPNz4B07ONpyyWpw==/split_lib_slice_6_apk.apk!/lib/x86, /data/app/com.example. -UG0Xr6gPNz4B07ONpyyWpw==/split_lib_slice_7_apk.apk!/lib/x86, /data/app/com.example. -UG0Xr6gPNz4B07ONpyyWpw==/split_lib_slice_8_apk.apk!/lib/x86, /data/app/com.example. -UG0Xr6gPNz4B07ONpyyWpw==/split_lib_slice_9_apk.apk!/lib/x86, /system/lib]]
11-13 13:12:15.939 5538-5538/com.example E/AndroidRuntime:     at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:134)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
        	... 16 more
    	Suppressed: java.io.IOException: No original dex files found for dex location /data/app/com.example-UG0Xr6gPNz4B07ONpyyWpw==/split_lib_resources_apk.apk
        at dalvik.system.DexFile.openDexFileNative(Native Method)
        at dalvik.system.DexFile.openDexFile(DexFile.java:354)
        at dalvik.system.DexFile.<init>(DexFile.java:101)
        at dalvik.system.DexFile.<init>(DexFile.java:75)
        at dalvik.system.DexPathList.loadDexFile(DexPathList.java:394)
        at dalvik.system.DexPathList.makeDexElements(DexPathList.java:354)
        at dalvik.system.DexPathList.<init>(DexPathList.java:164)
        at dalvik.system.BaseDexClassLoader.<init>(BaseDexClassLoader.java:74)
        at dalvik.system.BaseDexClassLoader.<init>(BaseDexClassLoader.java:65)
        at dalvik.system.PathClassLoader.<init>(PathClassLoader.java:64)
        at com.android.internal.os.ClassLoaderFactory.createClassLoader(ClassLoaderFactory.java:73)
        at com.android.internal.os.ClassLoaderFactory.createClassLoader(ClassLoaderFactory.java:88)
        at android.app.ApplicationLoaders.getClassLoader(ApplicationLoaders.java:74)
        at android.app.ApplicationLoaders.getClassLoader(ApplicationLoaders.java:40)
        at android.app.LoadedApk.createOrUpdateClassLoaderLocked(LoadedApk.java:727)
        at android.app.LoadedApk.getClassLoader(LoadedApk.java:810)
        at android.app.LoadedApk.getResources(LoadedApk.java:1032)
        at android.app.ContextImpl.createAppContext(ContextImpl.java:2345)
        at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5749)
        at android.app.ActivityThread.access$1100(ActivityThread.java:199)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1650)
        		... 6 more`

If you are referencing Flutter.createView() from the sample project, then I cannot get a reference to Flutter at all. Like "Flutter" will NOT be imported from the import io.flutter.facade.Flutter; because it doesn't exist, even though I added the Fat AAR to the project.

And yes, in my android-library project, I made sure to have the aarPlugin { includeAllInner...} block.

I'll keep playing with it, but those are the errors im getting. Will post if I get updates and any help would be greatly appreciated, thanks!

@comigor
Copy link
Contributor

comigor commented Nov 13, 2018

My library lib module registers a custom Activity (that extends from AppCompatActivity) and calls setContentView(Flutter.createView(this, lifecycle, initialRoute)).

The app is just used to login on my application and launch an intent with the activity registered on lib.

This facade namespace should be on Flutter module, maybe it's not being imported correctly.

@comigor
Copy link
Contributor

comigor commented Nov 13, 2018

@MichaelShnaider Also, I'm not sure why but I have to call ./gradlew assemble (the artifacts of the intermediates objects need to be built before your lib, that's the way the fatAAR plugin works) on the android/ folder to build all the modules or else the generated fatAAR won't come with the intermediates assets/classes.

@MichaelShnaider
Copy link
Author

MichaelShnaider commented Nov 14, 2018

@Igor1201 Ok cool, so right now you have the lib and the sample in the same project.
My goal is to make the fat AAR and use it in a completely separate project. Let me know if this is what you are trying to do as well.
Technically what you are doing is what I'm trying to do, but just to be certain, can you please try to do this, this is what I am trying to do:

1. Generate the fat AAR from the android-lib project with a /gradlew build command. (My FAT AAR is around 23.5 MB). android-lib contains a FlutterViewActivity I made that does Flutter.createView(...). So this activity displays the Flutter view with the plugins and stuff.

2. Make a brand new android project

3. Add the FAT AAR to the new project. I did this by dragging the Fat AAR into the /libs directory of the new Android project app-module and following the first answer of this stackoverflow post:
https://stackoverflow.com/questions/16682847/how-to-manually-include-external-aar-package-using-new-gradle-android-build-syst

4. Then from the MainActivity of the newly created class, in my onCreate method, I do:
Intent i = new Intent(this, FlutterViewActivity.class); startActivity(i);
The FlutterViewActivity class is my custom activity in the android-lib project which does the Flutter.createView(...) and displays the flutter stuff.

It is at this point when I run the Flutter application that I crash. Not sure if that was your end goal, but that was mine. If I simply import the android-library into the app module of the same Android project, then everything works. It breaks when I try to put the AAR into a different android project.

@comigor
Copy link
Contributor

comigor commented Nov 14, 2018

@MichaelShnaider That's exactly our goal too.

My library AAR file in release mode has ~6.1M, while the debug version comes with 24M.

The only difference of what you are doing is that I'm shipping the library to a private maven repo (using maven-publish+ this) and importing it as implementation 'com.example:my_library:1.0.0' on another android project, hosted on another repo; and launching a intent pointing to a custom activity that lives inside the AAR, just like the way you are doing.

Sorry I can't show you the repo, but that's the tree of the generated AAR:

my_library.aar (release)

➜ tree .
.
├── AndroidManifest.xml
├── R.txt
├── assets
│   ├── flutter_assets
│   │   ├── AssetManifest.json
│   │   ├── FontManifest.json
│   │   ├── LICENSE
│   │   ├── assets
│   │   │   └── ic_warning.svg
│   │   └── fonts
│   │       └── MaterialIcons-Regular.ttf
│   ├── flutter_shared
│   │   └── icudtl.dat
│   ├── isolate_snapshot_data
│   ├── isolate_snapshot_instr
│   ├── vm_snapshot_data
│   └── vm_snapshot_instr
├── classes.jar
├── jni
│   └── armeabi-v7a
│       └── libflutter.so
├── libs
│   ├── android-flutter-unspecified.jar
│   ├── flutter.jar
│   ├── io.flutter.plugins.pathprovider-path_provider-1.0-SNAPSHOT.jar
│   └── r-classes.jar
└── res
    ├── layout
    │   └── activity_my_library.xml
    └── values
        └── values.xml

And the contents of the JARs inside the lib/ folder:

android-flutter-unspecified.jar

➜ unzip -l android-flutter-unspecified.jar
Archive:  android-flutter-unspecified.jar
  Length      Date    Time    Name
---------  ---------- -----   ----
      614  12-31-1969 21:00   me/example/my_library/BuildConfig.class
     1523  12-31-1969 21:00   io/flutter/facade/Flutter$1.class
     2431  12-31-1969 21:00   io/flutter/facade/Flutter$2.class
     2437  12-31-1969 21:00   io/flutter/facade/Flutter.class
     1950  12-31-1969 21:00   io/flutter/facade/FlutterFragment.class
     1362  12-31-1969 21:00   io/flutter/plugins/GeneratedPluginRegistrant.class
---------                     -------
    10317                     6 files

flutter.jar

➜ unzip -l flutter.jar
Archive:  flutter.jar
  Length      Date    Time    Name
---------  ---------- -----   ----
     4253  12-31-1969 21:00   io/flutter/app/FlutterFragmentActivity.class
    12893  12-31-1969 21:00   io/flutter/app/FlutterActivityDelegate.class
     1611  12-31-1969 21:00   io/flutter/app/FlutterActivityDelegate$1.class
      748  12-31-1969 21:00   io/flutter/app/FlutterActivityEvents.class
      444  12-31-1969 21:00   io/flutter/app/FlutterActivityDelegate$ViewFactory.class
     7558  12-31-1969 21:00   io/flutter/app/FlutterPluginRegistry.class
     5207  12-31-1969 21:00   io/flutter/app/FlutterPluginRegistry$FlutterRegistrar.class
      894  12-31-1969 21:00   io/flutter/app/FlutterApplication.class
     4417  12-31-1969 21:00   io/flutter/app/FlutterActivity.class
     1289  12-31-1969 21:00   io/flutter/app/FlutterActivityDelegate$1$1.class
     8596  12-31-1969 21:00   io/flutter/plugin/editing/TextInputPlugin.class
     5942  12-31-1969 21:00   io/flutter/plugin/editing/InputConnectionAdaptor.class
    13900  12-31-1969 21:00   io/flutter/plugin/platform/PlatformViewsController.class
     2328  12-31-1969 21:00   io/flutter/plugin/platform/SingleViewPresentation$FakeWindowViewGroup.class
     1130  12-31-1969 21:00   io/flutter/plugin/platform/PlatformViewsController$1.class
     1625  12-31-1969 21:00   io/flutter/plugin/platform/VirtualDisplayController$1.class
     1277  12-31-1969 21:00   io/flutter/plugin/platform/VirtualDisplayController$OneTimeOnDrawListener$1.class
     1012  12-31-1969 21:00   io/flutter/plugin/platform/VirtualDisplayController$1$1.class
     9182  12-31-1969 21:00   io/flutter/plugin/platform/PlatformPlugin.class
      250  12-31-1969 21:00   io/flutter/plugin/platform/PlatformViewRegistry.class
     4019  12-31-1969 21:00   io/flutter/plugin/platform/SingleViewPresentation$WindowManagerHandler.class
     1357  12-31-1969 21:00   io/flutter/plugin/platform/PlatformViewRegistryImpl.class
      198  12-31-1969 21:00   io/flutter/plugin/platform/PlatformView.class
     1661  12-31-1969 21:00   io/flutter/plugin/platform/VirtualDisplayController$OneTimeOnDrawListener.class
     1004  12-31-1969 21:00   io/flutter/plugin/platform/PlatformViewFactory.class
     2486  12-31-1969 21:00   io/flutter/plugin/platform/SingleViewPresentation$PresentationState.class
     4871  12-31-1969 21:00   io/flutter/plugin/platform/VirtualDisplayController.class
     5013  12-31-1969 21:00   io/flutter/plugin/platform/SingleViewPresentation.class
     1503  12-31-1969 21:00   io/flutter/plugin/platform/SingleViewPresentation$PresentationContext.class
      617  12-31-1969 21:00   io/flutter/plugin/common/StandardMessageCodec$ExposedByteArrayOutputStream.class
      910  12-31-1969 21:00   io/flutter/plugin/common/FlutterException.class
     3770  12-31-1969 21:00   io/flutter/plugin/common/JSONMethodCodec.class
      438  12-31-1969 21:00   io/flutter/plugin/common/BinaryMessenger$BinaryMessageHandler.class
     1127  12-31-1969 21:00   io/flutter/plugin/common/PluginRegistry.class
      300  12-31-1969 21:00   io/flutter/plugin/common/PluginRegistry$NewIntentListener.class
      332  12-31-1969 21:00   io/flutter/plugin/common/PluginRegistry$PluginRegistrantCallback.class
     1063  12-31-1969 21:00   io/flutter/plugin/common/BinaryCodec.class
     2873  12-31-1969 21:00   io/flutter/plugin/common/EventChannel.class
     1951  12-31-1969 21:00   io/flutter/plugin/common/StringCodec.class
     3588  12-31-1969 21:00   io/flutter/plugin/common/JSONUtil.class
      317  12-31-1969 21:00   io/flutter/plugin/common/PluginRegistry$ViewDestroyListener.class
      288  12-31-1969 21:00   io/flutter/plugin/common/PluginRegistry$UserLeaveHintListener.class
      185  12-31-1969 21:00   io/flutter/plugin/common/ActivityLifecycleListener.class
     2637  12-31-1969 21:00   io/flutter/plugin/common/BasicMessageChannel$IncomingReplyHandler.class
     2144  12-31-1969 21:00   io/flutter/plugin/common/MethodChannel$IncomingMethodCallHandler$1.class
    10245  12-31-1969 21:00   io/flutter/plugin/common/StandardMessageCodec.class
     1712  12-31-1969 21:00   io/flutter/plugin/common/MethodCall.class
      442  12-31-1969 21:00   io/flutter/plugin/common/EventChannel$StreamHandler.class
      317  12-31-1969 21:00   io/flutter/plugin/common/PluginRegistry$ActivityResultListener.class
     3497  12-31-1969 21:00   io/flutter/plugin/common/StandardMethodCodec.class
     2033  12-31-1969 21:00   io/flutter/plugin/common/JSONMessageCodec.class
     3356  12-31-1969 21:00   io/flutter/plugin/common/BasicMessageChannel$IncomingMessageHandler.class
      426  12-31-1969 21:00   io/flutter/plugin/common/MethodChannel$MethodCallHandler.class
      359  12-31-1969 21:00   io/flutter/plugin/common/BasicMessageChannel$Reply.class
      619  12-31-1969 21:00   io/flutter/plugin/common/BinaryMessenger.class
     4767  12-31-1969 21:00   io/flutter/plugin/common/EventChannel$IncomingStreamRequestHandler.class
      562  12-31-1969 21:00   io/flutter/plugin/common/BasicMessageChannel$MessageHandler.class
      403  12-31-1969 21:00   io/flutter/plugin/common/MessageCodec.class
      343  12-31-1969 21:00   io/flutter/plugin/common/PluginRegistry$RequestPermissionsResultListener.class
      485  12-31-1969 21:00   io/flutter/plugin/common/MethodChannel$Result.class
     2932  12-31-1969 21:00   io/flutter/plugin/common/MethodChannel$IncomingMethodCallHandler.class
     2125  12-31-1969 21:00   io/flutter/plugin/common/PluginRegistry$Registrar.class
     3022  12-31-1969 21:00   io/flutter/plugin/common/EventChannel$IncomingStreamRequestHandler$EventSinkImplementation.class
      234  12-31-1969 21:00   io/flutter/plugin/common/EventChannel$1.class
      282  12-31-1969 21:00   io/flutter/plugin/common/BinaryMessenger$BinaryReply.class
     2278  12-31-1969 21:00   io/flutter/plugin/common/MethodChannel$IncomingResultHandler.class
     3939  12-31-1969 21:00   io/flutter/plugin/common/MethodChannel.class
      563  12-31-1969 21:00   io/flutter/plugin/common/MethodCodec.class
     1905  12-31-1969 21:00   io/flutter/plugin/common/BasicMessageChannel$IncomingMessageHandler$1.class
     4321  12-31-1969 21:00   io/flutter/plugin/common/BasicMessageChannel.class
      372  12-31-1969 21:00   io/flutter/plugin/common/EventChannel$EventSink.class
      255  12-31-1969 21:00   io/flutter/plugin/common/BasicMessageChannel$1.class
      631  12-31-1969 21:00   io/flutter/util/Preconditions.class
      842  12-31-1969 21:00   io/flutter/util/PathUtils.class
     1932  12-31-1969 21:00   io/flutter/view/ResourceCleaner$CleanTask.class
      792  12-31-1969 21:00   io/flutter/view/FlutterCallbackInformation.class
     2366  12-31-1969 21:00   io/flutter/view/AccessibilityBridge$Flag.class
     1004  12-31-1969 21:00   io/flutter/view/ResourcePaths.class
      977  12-31-1969 21:00   io/flutter/view/VsyncWaiter.class
      736  12-31-1969 21:00   io/flutter/view/VsyncWaiter$1.class
      326  12-31-1969 21:00   io/flutter/view/TextureRegistry.class
     1377  12-31-1969 21:00   io/flutter/view/FlutterView$AccessibilityFeature.class
     1859  12-31-1969 21:00   io/flutter/view/FlutterView$TouchExplorationListener.class
      875  12-31-1969 21:00   io/flutter/view/AccessibilityBridge$CustomAccessibilityAction.class
      343  12-31-1969 21:00   io/flutter/view/TextureRegistry$SurfaceTextureEntry.class
     1473  12-31-1969 21:00   io/flutter/view/AccessibilityBridge$TextDirection.class
     1928  12-31-1969 21:00   io/flutter/view/FlutterMain$ImmutableSetBuilder.class
     1493  12-31-1969 21:00   io/flutter/view/FlutterView$SurfaceTextureRegistryEntry$1.class
     1549  12-31-1969 21:00   io/flutter/view/FlutterView$1.class
    10530  12-31-1969 21:00   io/flutter/view/FlutterMain.class
     1202  12-31-1969 21:00   io/flutter/view/FlutterView$ZeroSides.class
    32640  12-31-1969 21:00   io/flutter/view/FlutterView.class
     1955  12-31-1969 21:00   io/flutter/view/FlutterNativeView$1.class
     2549  12-31-1969 21:00   io/flutter/view/AccessibilityBridge$Action.class
      252  12-31-1969 21:00   io/flutter/view/FlutterView$FirstFrameListener.class
    12054  12-31-1969 21:00   io/flutter/view/AccessibilityBridge$SemanticsObject.class
     4371  12-31-1969 21:00   io/flutter/view/ResourceExtractor.class
      262  12-31-1969 21:00   io/flutter/view/FlutterView$Provider.class
      949  12-31-1969 21:00   io/flutter/view/FlutterView$ViewportMetrics.class
      645  12-31-1969 21:00   io/flutter/view/FlutterMain$Settings.class
      905  12-31-1969 21:00   io/flutter/view/ResourceCleaner$1.class
     1504  12-31-1969 21:00   io/flutter/view/ResourceCleaner.class
    24206  12-31-1969 21:00   io/flutter/view/AccessibilityBridge.class
     1050  12-31-1969 21:00   io/flutter/view/ResourceCleaner$2.class
     2538  12-31-1969 21:00   io/flutter/view/FlutterView$SurfaceTextureRegistryEntry.class
      421  12-31-1969 21:00   io/flutter/view/FlutterRunArguments.class
     8709  12-31-1969 21:00   io/flutter/view/FlutterNativeView.class
     5538  12-31-1969 21:00   io/flutter/view/ResourceExtractor$ExtractTask.class
      898  12-31-1969 21:00   io/flutter/view/ResourceExtractor$1.class
     1993  12-31-1969 21:00   io/flutter/view/FlutterView$AnimationScaleObserver.class
---------                     -------
   316676                     110 files

io.flutter.plugins.pathprovider-path_provider-1.0-SNAPSHOT.jar

➜ unzip -l io.flutter.plugins.pathprovider-path_provider-1.0-SNAPSHOT.jar
Archive:  io.flutter.plugins.pathprovider-path_provider-1.0-SNAPSHOT.jar
  Length      Date    Time    Name
---------  ---------- -----   ----
      606  12-31-1969 21:00   io/flutter/plugins/pathprovider/BuildConfig.class
     2960  12-31-1969 21:00   io/flutter/plugins/pathprovider/PathProviderPlugin.class
---------                     -------
     3566                     2 files

r-classes.jar

➜ unzip -l r-classes.jar
Archive:  r-classes.jar
  Length      Date    Time    Name
---------  ---------- -----   ----
        0  11-14-2018 13:30   META-INF/
       25  11-14-2018 13:30   META-INF/MANIFEST.MF
        0  11-14-2018 13:30   io/
        0  11-14-2018 13:30   io/flutter/
        0  11-14-2018 13:30   io/flutter/plugins/
        0  11-14-2018 13:30   io/flutter/plugins/pathprovider/
      292  11-14-2018 13:30   io/flutter/plugins/pathprovider/R.class
        0  11-14-2018 13:30   com/
        0  11-14-2018 13:30   com/example/
        0  11-14-2018 13:30   com/example/my_library/
      985  11-14-2018 13:30   com/example/my_library/R.class
      562  11-14-2018 13:30   com/example/my_library/R$bool.class
     2235  11-14-2018 13:30   com/example/my_library/R$id.class
     2200  11-14-2018 13:30   com/example/my_library/R$styleable.class
     1496  11-14-2018 13:30   com/example/my_library/R$style.class
      582  11-14-2018 13:30   com/example/my_library/R$string.class
      995  11-14-2018 13:30   com/example/my_library/R$color.class
     1877  11-14-2018 13:30   com/example/my_library/R$dimen.class
      645  11-14-2018 13:30   com/example/my_library/R$integer.class
     1533  11-14-2018 13:30   com/example/my_library/R$layout.class
     1444  11-14-2018 13:30   com/example/my_library/R$attr.class
     1261  11-14-2018 13:30   com/example/my_library/R$drawable.class
---------                     -------
    16132                     23 files

Hope this helps!

@rafaelring
Copy link

@MichaelShnaider What is the stacktrace of your crash?

@MichaelShnaider
Copy link
Author

@rafaelring the crash I have is above: #23944 (comment)

@rafaelring
Copy link

rafaelring commented Nov 14, 2018

@MichaelShnaider Can you send also the tree of your fat AAR files (unzip -l your-fat-aar.aar), please? It seems like the generated AAR is failing to contain all the classes and maybe the flutter resources

@MichaelShnaider
Copy link
Author

MichaelShnaider commented Nov 14, 2018

@rafaelring Yea, maybe you are right, this is my debug aar:

Archive:  flutter_wrapper_module-debug.aar
  Length      Date    Time    Name
---------  ---------- -----   ----
        0  11-14-2018 09:46   res/
        0  11-14-2018 09:46   res/layout/
      241  11-14-2018 09:46   res/layout/flutter_activity.xml
        0  11-14-2018 09:46   res/values/
      123  11-14-2018 09:46   res/values/values.xml
      449  11-14-2018 09:46   AndroidManifest.xml
     1765  11-14-2018 09:46   classes.jar
        0  11-14-2018 09:46   libs/
   165606  11-14-2018 09:46   libs/flutter.jar
    10520  11-14-2018 09:46   libs/rs.jar
     2266  11-14-2018 09:46   libs/path_provider.jar
       22  11-14-2018 09:46   libs/flutter-x86.jar
    83109  11-14-2018 09:46   R.txt
        0  11-14-2018 09:46   jni/
        0  11-14-2018 09:46   jni/armeabi-v7a/
 11876340  11-14-2018 09:46   jni/armeabi-v7a/libflutter.so
        0  11-14-2018 09:46   jni/x86/
 16056652  11-14-2018 09:46   jni/x86/libflutter.so
        0  11-14-2018 09:46   jni/x86_64/
 17297992  11-14-2018 09:46   jni/x86_64/libflutter.so
        0  11-14-2018 09:46   assets/
        0  11-14-2018 09:46   assets/flutter_assets/
   606282  11-14-2018 09:46   assets/flutter_assets/LICENSE
  2966622  11-14-2018 09:46   assets/flutter_assets/vm_snapshot_data
   441591  11-14-2018 09:46   assets/flutter_assets/isolate_snapshot_data
      109  11-14-2018 09:46   assets/flutter_assets/AssetManifest.json
 14738981  11-14-2018 09:46   assets/flutter_assets/kernel_blob.bin
      208  11-14-2018 09:46   assets/flutter_assets/FontManifest.json
        0  11-14-2018 09:46   assets/flutter_assets/packages/
        0  11-14-2018 09:46   assets/flutter_assets/packages/cupertino_icons/
        0  11-14-2018 09:46   assets/flutter_assets/packages/cupertino_icons/assets/
    97680  11-14-2018 09:46   assets/flutter_assets/packages/cupertino_icons/assets/CupertinoIcons.ttf
        0  11-14-2018 09:46   assets/flutter_assets/fonts/
   134640  11-14-2018 09:46   assets/flutter_assets/fonts/MaterialIcons-Regular.ttf
        0  11-14-2018 09:46   assets/flutter_shared/
   883280  11-14-2018 09:46   assets/flutter_shared/icudtl.dat
---------                     -------
 65364478                     36 files

here is release:

Archive:  flutter_wrapper_module-release.aar
  Length      Date    Time    Name
---------  ---------- -----   ----
        0  11-14-2018 11:14   res/
        0  11-14-2018 11:14   res/layout/
      241  11-14-2018 11:14   res/layout/flutter_activity.xml
        0  11-14-2018 11:14   res/values/
      123  11-14-2018 11:14   res/values/values.xml
      449  11-14-2018 11:14   AndroidManifest.xml
     1696  11-14-2018 11:14   classes.jar
        0  11-14-2018 11:14   libs/
   165606  11-14-2018 11:14   libs/flutter.jar
     9893  11-14-2018 11:14   libs/rs.jar
    83109  11-14-2018 11:14   R.txt
        0  11-14-2018 11:14   jni/
        0  11-14-2018 11:14   jni/armeabi-v7a/
  5506404  11-14-2018 11:14   jni/armeabi-v7a/libflutter.so
        0  11-14-2018 11:14   assets/
    22904  11-14-2018 11:14   assets/vm_snapshot_data
  2580464  11-14-2018 11:14   assets/isolate_snapshot_instr
  1848648  11-14-2018 11:14   assets/isolate_snapshot_data
    11424  11-14-2018 11:14   assets/vm_snapshot_instr
        0  11-14-2018 11:14   assets/flutter_assets/
   606282  11-14-2018 11:14   assets/flutter_assets/LICENSE
      109  11-14-2018 11:14   assets/flutter_assets/AssetManifest.json
      208  11-14-2018 11:14   assets/flutter_assets/FontManifest.json
        0  11-14-2018 11:14   assets/flutter_assets/packages/
        0  11-14-2018 11:14   assets/flutter_assets/packages/cupertino_icons/
        0  11-14-2018 11:14   assets/flutter_assets/packages/cupertino_icons/assets/
    97680  11-14-2018 11:14   assets/flutter_assets/packages/cupertino_icons/assets/CupertinoIcons.ttf
        0  11-14-2018 11:14   assets/flutter_assets/fonts/
   134640  11-14-2018 11:14   assets/flutter_assets/fonts/MaterialIcons-Regular.ttf
        0  11-14-2018 11:14   assets/flutter_shared/
   883280  11-14-2018 11:14   assets/flutter_shared/icudtl.dat
---------                     -------
 11953160                     31 files

@rafaelring
Copy link

@MichaelShnaider Got it, this is a problem we've stumbled into also. What happens is that this version of the fat aar plugin you're using (2.0.1) has an issue on this conditions: when merging the dependencies it only considers the name of the artifact. Because there's a :flutter module (generated by the module template) and a flutter.jar provided by the flutter itself, both artifacts have the same name and so the plugin will overwrite one of them with the other. This was fixed at Mobbeel/fataar-gradle-plugin#10 so just bumping the plugin to the 2.0.3 version will fix your crash

@MichaelShnaider
Copy link
Author

@rafaelring HAHAHA OMG YOU GOT IT EXACTLY! Thanks so much for your help, @Igor1201 and @rafaelring, I appreciate it a lot! You guys are amazing!

@rafaelring
Copy link

@MichaelShnaider Nice, just a quick follow up question if you don't mind, did you get it working with which flutter version? On our setup we needed to make a change to flutter in order to get the icudtl.dat included (#23782). Did it worked for you directly?

@MichaelShnaider
Copy link
Author

MichaelShnaider commented Nov 14, 2018

@rafaelring I had to manually drag the icudtl.dat file into the flutter project under path_to_flutter_project/.android/Flutter/src/main/assets/flutter_shared/icudtl.dat

So no, it did not work directly, but hopefully that will be fixed in the future.

Flutter 0.11.1-pre.127 • channel master • https://github.com/flutter/flutter.git
Framework • revision ae2b215efe (5 days ago) • 2018-11-09 00:40:29 -0800
Engine • revision b2479f8d29
Tools • Dart 2.1.0 (build 2.1.0-dev.9.3 9c07fb64c4)

@rafaelring
Copy link

@MichaelShnaider Got it. That's why we did that PR so then you don't have to copy it manually anymore as it will work directly with the generated files. Thanks

@jelenalecic
Copy link

any news on this issue? is there any hope for this PR to be merged soon? :)
does this PR
https://github.com/flutter/flutter/pull/23782
solves the plugin issue or just missing icudtl.dat?
@matthew-carroll

@rafaelring
Copy link

@jelenacarnegie The PR #23782 fixes the missing icudtl.dat. The plugins issue can be solved by generating a Fat AAR from your project (one way is using the https://github.com/Mobbeel/fataar-gradle-plugin).
If it makes sense, maybe we can look into making flutter generate a FatAAR directly from a module project without requiring any external plugins. This should not be too hard to do.

@zoechi zoechi added the tool Affects the "flutter" command-line tool. See also t: labels. label Dec 13, 2018
@xenixcorp
Copy link

@MichaelShnaider Hello, i have same issue like yours #23944 (comment) with fat-aar-plugin version 2.0.1. How do you solve it?

I Try using fat-aar-plugin version 2.0.3 can't build aar. The error is 'R.txt cannot generate'.
Thanks.

@AresVampire
Copy link

I am facing the same issue. Please help me.

@AresVampire
Copy link

AresVampire commented Jan 19, 2019

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':flutter_card_io:copyReleaseDependencies'.
> java.io.FileNotFoundException: /Volumes/Work/Work/Flutter/Craypay/Craypay/build/flutter_card_io/tmp/copyReleaseDependencies/release/R.txt (No such file or directory)

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

@tarek360
Copy link

In flutter/packages/flutter_tools/gradle/flutter.gradle

findByPath(":app:merge${variant.name.capitalize()}Assets")

:app could be a problem if the project has different entry point, it might be in a different name or path.
For example, my project entry module (app module) is not in the root directory,
it's in /presentation/app
so I needed to update that line to be

findByPath(":presentation:app:merge${variant.name.capitalize()}Assets")

or the flutter_shared folder won't be copied to my apk.

some how we need to remove :app and make it dynamic, and for now I think we should have a hint about that in the documentation here.

@lsp9876
Copy link

lsp9876 commented Apr 2, 2019

@Igor1201 I tried adding the "api project" lines that you recommended, but I get the error:

FAILURE: Build failed with an exception.

* What went wrong:
Circular dependency between the following tasks:
:flutter:generateDebugRFile
\--- :flutter:generateDebugRFile (*)

(*) - details omitted (listed previously)


* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 1s

I'm not sure where the issue lies, but here is my ./android/build.gradle:

// Generated file. Do not edit.

buildscript {
    repositories {    
            google()
            jcenter()
            maven { url "https://plugins.gradle.org/m2/" }
            
        }

    dependencies {
        classpath 'com.android.tools.build:gradle:3.2.1'
        // Mobbeel to generate the fat aar.
        classpath "com.mobbeel.plugin:fat-aar:2.0.1"
        
    }
}

allprojects {
    repositories {
        google()
        jcenter()
        maven { url "https://plugins.gradle.org/m2/" }
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}`

Here is my ./android/Flutter/build.gradle

// Generated file. Do not edit.
apply plugin: "com.mobbeel.plugin"

def localProperties = new Properties()
def localPropertiesFile = new File(buildscript.sourceFile.parentFile.parentFile, 'local.properties')
if (localPropertiesFile.exists()) {
    localPropertiesFile.withReader('UTF-8') { reader ->
        localProperties.load(reader)
    }
}

def flutterRoot = localProperties.getProperty('flutter.sdk')
if (flutterRoot == null) {
    throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
}

def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
if (flutterVersionCode == null) {
    flutterVersionCode = '1'
}

def flutterVersionName = localProperties.getProperty('flutter.versionName')
if (flutterVersionName == null) {
    flutterVersionName = '1.0'
}


apply plugin: 'com.android.library'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"

android {
    compileSdkVersion 27
    

    defaultConfig {
        minSdkVersion 16
        targetSdkVersion 27
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }

    aarPlugin {
        includeAllInnerDependencies true  // It's false for default
    }


}


flutter {
    source '../..'
}

dependencies {
    testImplementation 'junit:junit:4.12'
    implementation 'com.android.support:support-v13:27.1.1'
    implementation 'com.android.support:support-annotations:27.1.1'
    api project(':flutter')
    api project(':path_provider') 
}

It's possible I added the "api project" lines in the wrong location or something

hi, I'm really curious to know how you solve the problem. I don’t know what I should do after that

@comigor
Copy link
Contributor

comigor commented Apr 2, 2019

@lsp9876 I think the issue here is that you are editing the generated project file, and not creating another module that imports the generated one (and use fataar on it).

What you should do is:

  • Let flutter generate its project (on $PROJECT_ROOT/$LIBNAME_flutter/.android).
  • Create a lib module (on $PROJECT_ROOT/android/$LIBNAME), which imports project(:flutter), uses fataar, etc.
  • Create a sample app project (on $PROJECT_ROOT/android/sample), which imports both project(:flutter) and project(:$LIBNAME).

Also, I'm using fataar v2.0.3.

@lsp9876
Copy link

lsp9876 commented Apr 3, 2019

@Igor1201
i got it. i will try that, thanks a lot.

@TinoGuo
Copy link

TinoGuo commented Apr 4, 2019

@Igor1201 I followed your steps, but I got an empty .aar file.

lib module imports flutter and path_provider modules.
app module imports lib module.
generate aar file from lib module.

Screen Shot 2019-04-04 at 16 19 03

flutter version:

[✓] Flutter (Channel beta, v1.3.8, on Mac OS X 10.14.4 18E226, locale en-US)

fataar version: 2.0.3

Anything wrong? Thanks.

@TinoGuo
Copy link

TinoGuo commented Apr 7, 2019

@Igor1201 It seems the wrong gradle plugin version lead to the empty lib

@comigor
Copy link
Contributor

comigor commented Apr 8, 2019

@TinoGuo I'm sorry I couldn't reach you sooner.
Did you manage to do it? Do you know which gradle plugin version work and which didn't?

@TinoGuo
Copy link

TinoGuo commented Apr 9, 2019

@Igor1201 Finally, I found a solution.

DONT just run ./gradlew $MODULENAME:assembleDebug, it just creates a empty aar.

run ./gradlew clean assembleDebug to build a sample app, then the needed aar in $MODULENAME/build/outputs/aar/$MODULENAME-debug.aar.

In addition, this only worked in gradle plugin 3.1.4 no matter what version of gradle.

@comigor
Copy link
Contributor

comigor commented Apr 12, 2019

Strange, maybe it's a bug on fataar. But glad you could achieve it!

@mahendramahi
Copy link

Use case

In my project we have ios and android native project. But after heard about flutter we decide that new functionality will develop into flutter module ( flutter create -t module project_name ) and finish work on flutter, we export .aar file from flutter project.

Now go to my android project and import flutter exported .aar file in android project as module or lib. for reference see the image
Untitled

After import we analyze .aar just like .apk file and here are image for reference
analyze

How can we call dart route page from Android app

`
@OverRide
protected void onCreate(Bundle savedInstanceState){
Flutter.startInitialization(getApplicationContext());
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
DisplayMetrics displayMetrics=new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
height=displayMetrics.heightPixels;
width=displayMetrics.widthPixels;

    View flutterView=Flutter.createView(
    MainActivity.this,
    getLifecycle(),
    "/"
    );
    FrameLayout.LayoutParams layout=new FrameLayout.LayoutParams(width,height);

    addContentView(flutterView,layout);
    }`

Call this code from my android activity ..
and we are successfully able to load flutter view on android activity
and for android we export app.framwork and flutter.framwork , ios app also able to load same view as like android(save time of development same thing in different lang or on difference platform )

issue

Now we create other module in flutter and import same as last time. during the import .aar we can change name of module using android studio. Here are we attaching image reference.

next

Now you can see the .so file in second .aar file with the same name of last one .aar file..

when we run this it gives error
More than one file was found with OS independent path libflutter.so'

@vishna
Copy link

vishna commented Aug 7, 2019

for me it seems to be working if aar package is release but fails to load plugins if a debug aar is used:

[✓] Flutter (Channel master, v1.8.4-pre.129, on Mac OS X 10.14.6 18G87, locale en-DE)
    • Flutter version 1.8.4-pre.129 at /Users/vishna/flutter
    • Framework revision 5756e2dcd0 (8 hours ago), 2019-08-07 04:50:25 -0400
    • Engine revision 9bfa4f53cd
    • Dart version 2.5.0 (build 2.5.0-dev.1.0 c262cbd414)

hopefully this sheds some light on the issue

@rajapanidepu
Copy link

@blasten
I see that you have been working on this, 1d2eaaf#diff-821e834d393664a9c4a3f016f13046d9L94

Do you have any update on how we can include flutter plugins into AAR file or Maven locale repo?

Thanks in advance.

@xster
Copy link
Member

xster commented Nov 15, 2019

I'm going to tentatively close this bug now.

See https://github.com/flutter/flutter/wiki/Add-Flutter-to-existing-apps#1-depend-on-the-android-archive-aar.

The 'official' flutter build aar command should by default include the module's dependent plugins.

@xster xster closed this as completed Nov 15, 2019
@github-actions
Copy link

This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 14, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
a: existing-apps Integration with existing apps via the add-to-app flow c: crash Stack traces logged to the console platform-android Android applications specifically t: gradle "flutter build" and "flutter run" on Android tool Affects the "flutter" command-line tool. See also t: labels.
Projects
None yet
Development

No branches or pull requests