6

When creating a plugin project in Flutter, an example app, that is using the plugin, is added in a subfolder of the plugin project. What needs to be done to add a second "example" app to the plugin folder?

So far I have:

  1. Copied and renamed the example folder to (let's call it) app2.

  2. Adjusted the package names at the android manifest files of app2.

  3. Renamed pluginrootfolder/app2/pluginname_example.iml to pluginrootfolder/app2/pluginname_app2.iml (to reflect the name of the second app).

  4. In the .iml file of the plugin project (the root folder): Copied and adjusted the exclude folder directive to reflect app2

      <excludeFolder url="file://$MODULE_DIR$/app2/.dart_tool" />
      <excludeFolder url="file://$MODULE_DIR$/app2/.pub" />
      <excludeFolder url="file://$MODULE_DIR$/app2/build" />
    
  5. Run Flutter clean and Flutter pub get in both the plugins root directory and app2's directory.

Problem now is that app2 causes 1k+ Target of URI doesn't exist: error messages - from packages (like provider and json_annotation) to classes in the plugin's root project. Do you have any ideas what's wrong here or how to fix it?

SePröbläm
  • 5,142
  • 6
  • 31
  • 45

2 Answers2

0

Firstly, please give a full GitHub reproducible repository and link it here so I can examine. And also paste (e.g. using github gist) the long log. Please comment to this answer so I can examine more.

"In the .iml file of the plugin project (the root folder)" - indeed not that needed. iml is for intellij idea, and is unrelated to flutter. so should not error even with wrong iml. You can even safely delete iml and when you import that module in intellij it will auto recreate.

Have you modified pubspec.yaml? e.g. the package name in it.

And, where is your plugin located, relative to your app2? In example app, the default pubspec.yaml uses path: ../ to point to your plugin. So if your app2 does not have .. as the plugin path you should change this as well.

Anyway, paste your log and give a reproducible sample please...

ch271828n
  • 15,854
  • 5
  • 53
  • 88
0

I suspect your issue is in the dependency tree. Your example2 project does not seem to point to the project above it. The only manual edits you need are in the pubspec.yaml. In the dependencies for the second example project.yaml file, include the path to the root project. For example:

dependencies:
  <YOUR_ROOT_PROJECT>:
    path: ../
  flutter:
    sdk: flutter

Including that should map the decencies of the root over with pub.get. That should take care of the Target of URI doesn't exist errors.

Since you are using .iml files, I assume you're using an IntelliJ/JetBrains IDE. Creating example subprojects can be done without all of the manual work you listed.

You don't have to copy the files themselves manually to create a second example. You can simply right-click on the project root and select new module. Choose Flutter. The project type is Application.

Secondly, you don't have to add the second project to the exclude folders.

Dharman
  • 30,962
  • 25
  • 85
  • 135
Paul
  • 352
  • 2
  • 3