1

i'm trying to add a local library to a flutter plugin project. the library is created directly in the root folder of the flutter project (not in the android folder) So here is the structure: MyFlutterProject:

_ lib
   __ flutterPlugin.dart
_ MyLibrary   
   __ build.gradle
   __ setting.gradle
   __ src
   __ ...
_ Android
   __ build.gradle
   __ ...
[...]

This is my [android] build.gradle file:

group 'org.example.myproject'
version '1.0'

buildscript {
    repositories {
        google()
        jcenter()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:3.5.0'
    }
}

rootProject.allprojects {
    repositories {
        google()
        jcenter()
    }
}

apply plugin: 'com.android.library'

android {
    compileSdkVersion 28

    defaultConfig {
        minSdkVersion 16
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }
    lintOptions {
        disable 'InvalidPackage'
    }
}

dependencies {
    implementation project(':myviewer')
}

And this is my [android] setting.gradle file:

rootProject.name = 'Mywidget'
include ':myviewer'
project(':myviewer').projectDir = new File('../myviewer')

When i try flutter run, here is the error:

flutter run Launching lib/main.dart on Aquaris U2 in debug mode... FAILURE: Build failed with an exception.

  • Where: Build file '/user/path/dev/FlutterPlugin/myproject/android/build.gradle' line: 37

  • What went wrong: A problem occurred evaluating project ':mywidget'.

Project with path ':myviewer' could not be found in project ':mywidget'.

  • 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 908ms
    Running Gradle task 'assembleDebug'...
    Running Gradle task 'assembleDebug'... Done
    2,1s Gradle task assembleDebug failed with exit code 1

Any idea on how to make it work?

Thank you

Arnaud Delubac
  • 759
  • 6
  • 13

1 Answers1

0

I found this solution that put me on the right track. After building the .aar using gradle aR in command line, i've created the folder libs in my android folder and the just add this line to my root build.gradle implementation fileTree(dir: 'libs', include: ['*.aar']), more explanation about this on developper.android web site

Arnaud Delubac
  • 759
  • 6
  • 13
  • 1
    `> A failure occurred while executing com.android.build.gradle.internal.tasks.Workers$ActionFacade => Non-directory inputs must have .jar extension` , this is the error i receive on running `flutter run` – Arnaud Delubac Dec 19 '19 at 09:51
  • Did you slove the comment's issue? I met the same problem, but have no idea to slove it :( – Tokenyet Jan 22 '20 at 18:06
  • 1
    It's so suck that I made a `Invalid Cache/Restart` with Android Studio not working, but I use `gradlew clean`, and everything works as usual... Another annoying cache bug, hope this could help someone... – Tokenyet Jan 22 '20 at 18:57