将Android项目导入Flutter包

3

我正在开发一个Flutter应用程序,它使用了我自己的Flutter软件包vocsy_epub_viewer(https://github.com/vongrad/vocsy_epub_viewer)的分支,因为我需要对其进行一些更改。

我已经在pubspec.yaml中引入了插件,并且这部分工作正常:

dev_dependencies:
  vocsy_epub_viewer:
    path: dependencies/vocsy_epub_viewer

vocsy_epub_viewer包含一个Flutter插件,作为调用一些平台特定代码的桥梁 - 对于Android,它使用vocsy_epub_viewer_android_folioreader。我也制作了这个Android包的分支(https://github.com/vongrad/vocsy_epub_viewer_android_folioreader),因为我需要对其进行更改。

在Flutter包的dependencies/vocsy_epub_viewer/android/build.gradle文件中,引用了Android包:

dependencies {
    implementation 'com.github.kaushikgodhani:vocsy_epub_viewer_android_folioreader:V3'
}

但是我需要让它从本地文件夹中引用,因为它是被克隆的(./vocsy_epub_viewer_android_folioreader)。

项目结构如下:

flutter project root
    dependencies
        vocsy_epub_viewer
            android
                settings.gradle
                build.gradle
                
    android
        settings.gradle
        build.gradle
    ios
    lib
    ...
    
vocsy_epub_viewer_android_folioreader  <--- this plugin needs to be included within vocsy_epub_viewer/android
    folioreader
        settings.gradle
        build.gradle
    settings.gradle
    build.gradle

我已经尝试将它包含在以下内容中:

dependencies/vocsy_epub_viewer/android/settings.gradle

include ':folioreader'
project(':folioreader').projectDir = file('C:\\Users\\test\\Documents\\Projects\\vocsy_epub_viewer_android_folioreader')

dependencies/vocsy_epub_viewer/android/build.gradle

dependencies {
    implementation "com.folioreader:folioreader" <-- attempt to import the package from a local folder
    // implementation 'com.github.kaushikgodhani:vocsy_epub_viewer_android_folioreader:V3' <-- original import
}

但似乎它不起作用。如果我能得到如何做这个的建议,我将非常感激。

编辑: 我也尝试了更改dependencies/vocsy_epub_viewer/android/build.gradle,如@Sajjad所建议的:

implementation project(':folioreader')

但是遇到了以下错误:

FAILURE: Build failed with an exception.

* Where:
Build file 'C:\Users\test\Documents\Projects\waily\dependencies\vocsy_epub_viewer\android\build.gradle' line: 40

* What went wrong:
A problem occurred evaluating project ':vocsy_epub_viewer'.
> Project with path ':folioreader' could not be found in project ':vocsy_epub_viewer'.

我希望这能够帮到您:https://dev59.com/KWEi5IYBdhLWcg3wsODc#21038488 - Mukund Jogi
新建建议 :) 将 file('C:\\Users\\test\\Documents\\Projects\\vocsy_epub_viewer_android_folioreader') 更改为 file('C:\\Users\\test\\Documents\\Projects\\vocsy_epub_viewer_android_folioreader\\folioreader') - Sajjad
我已经尝试过了,它产生了与“编辑”中相同的错误。 - Adam
1个回答

1

请按照以下步骤操作:

1. 从https://jitpack.io引用您的自定义vocsy_epub_viewer_android_folioreader


2. 将以下代码添加到您的flutterRoot > vocsy_epub_viewer > android > build.gradle文件的repositories末尾:

allprojects {
    repositories {
        ...
        maven { url 'https://jitpack.io' }
    }
}

步骤2. 添加依赖

dependencies {
            implementation 'com.github.vongrad:vocsy_epub_viewer_android_folioreader:master-SNAPSHOT'
    }


谢谢您的建议。有没有办法不从远程git仓库引用,而是从本地目录引用?原因是我不想在开发过程中提交更改到git仓库,以便能够在Flutter应用程序中测试它。 - Adam
@Adam,我觉得你已经完成了99%的任务,请尝试点击下面的链接并告诉我们出现了什么错误:https://stackoverflow.com/a/46100715/6813907 - Sajjad
例如,我猜测 implementation "com.folioreader:folioreader" 应该改为 compile project(path: ':folioreader') - Sajjad
也许这个语法有效:implementation project(': folioreader'),来自原始文档 https://docs.gradle.org/current/userguide/declaring_dependencies.html#sub:project_dependencies。 - Sajjad
谢谢你的建议。我尝试应用了你的更改,但是没有成功。请查看更新后的问题。 - Adam

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接