flutter / flutter

Flutter makes it easy and fast to build beautiful apps for mobile and beyond
https://flutter.dev
BSD 3-Clause "New" or "Revised" License
164.91k stars 27.16k forks source link

Integration flutter to app, file path issue when indexing on AppCode IDE #57989

Open krmao opened 4 years ago

krmao commented 4 years ago

Steps to Reproduce

  1. follow https://flutter.dev/docs/development/add-to-app/ios/project-setup#option-a---embed-with-cocoapods-and-the-flutter-sdk

Logs

bug in Appcode https://youtrack.jetbrains.com/issue/OC-17593

solution

https://www.kikt.top/posts/flutter/channel/flutter-ios-spec-edit/ just modify podhelper.rb

#  plugin_pods.map do |r|
#    symlink = File.join(symlinks_dir, r[:name])
#    FileUtils.rm_f(symlink)
#    File.symlink(r[:path], symlink)
#    pod r[:name], :path => File.join(symlink, 'ios'), :inhibit_warnings => true
#  end

to

   plugin_pods.map { |p|
      name = p[:name]
      path = p[:path]
      specPath = "#{path}/ios/#{name}.podspec"
      pod p[:name],:path=>specPath
   }
TahaTesser commented 4 years ago

Hi @krmao Can you please the issue in detail? What issue occurs with reproducible steps and what your solution does? Also please provide your flutter run --verbose? Thank you

krmao commented 4 years ago

@TahaTesser

flutter doctor -v

flutter doctor -v
[✓] Flutter (Channel unknown, v1.17.1, on Mac OS X 10.15.4 19E287, locale zh-Hans-CN)
    • Flutter version 1.17.1 at /Users/krmao/workspace/flutter
    • Framework revision f7a6a7906b (3 weeks ago), 2020-05-12 18:39:00 -0700
    • Engine revision 6bc433c6b6
    • Dart version 2.8.2

[✓] Android toolchain - develop for Android devices (Android SDK version 29.0.3)
    • Android SDK at /Users/krmao/sdks/android/sdk
    • Platform android-R, build-tools 29.0.3
    • ANDROID_HOME = /Users/krmao/sdks/android/sdk
    • Java binary at: /Applications/Android Studio 3.4.1.app/Contents/jre/jdk/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 1.8.0_212-release-1586-b4-5784211)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 11.3.1)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Xcode 11.3.1, Build version 11C504
    • CocoaPods version 1.9.1

[✓] Android Studio (version 3.6)
    • Android Studio at /Applications/Android Studio 3.4.1.app/Contents
    • Flutter plugin version 45.1.1
    • Dart plugin version 192.7761
    • Java version OpenJDK Runtime Environment (build 1.8.0_212-release-1586-b4-5784211)

[✓] IntelliJ IDEA Ultimate Edition (version 2019.3.3)
    • IntelliJ at /Applications/IntelliJ IDEA.app
    • Flutter plugin version 45.1.2
    • Dart plugin version 193.6494.35

[✓] VS Code (version 1.45.0)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.10.1

[✓] Connected device (1 available)
    • iPhone 11 Pro Max • DA7463AE-EFD1-4242-961E-D58A3E2657C4 • ios • com.apple.CoreSimulator.SimRuntime.iOS-13-3 (simulator)

• No issues found!

problems

add flutter to exist App with the official step option A, in Xcode everything is ok, but in AppCode will never success to indexing the flutter plugin files, because the file path contains "../.." .

if file path not contains "../.." , then AppCode is success to indexing

just modify podhelper.rb

#  plugin_pods.map do |r|
#    symlink = File.join(symlinks_dir, r[:name])
#    FileUtils.rm_f(symlink)
#    File.symlink(r[:path], symlink)
#    pod r[:name], :path => File.join(symlink, 'ios'), :inhibit_warnings => true
#  end

to

   plugin_pods.map { |p|
      name = p[:name]
      path = p[:path]
      specPath = "#{path}/ios/#{name}.podspec"
      pod p[:name],:path=>specPath
   }
jmagman commented 4 years ago

I don't understand the issue. What does "will never success to indexing the flutter plugin files, because the file path contains "../.." ." mean? The path to what contains that? What error are you seeing?

Your suggested change won't work on multiple machines. p[:path] is an absolute path to your pub cache. If your colleague checks out your repo, the Podfile.lock won't point to a path on their machine. That's what the symlinking part solves.

   plugin_pods.map { |p|
      name = p[:name]
      path = p[:path]
      specPath = "#{path}/ios/#{name}.podspec"
      pod p[:name],:path=>specPath
   }
jmagman commented 4 years ago

https://www.kikt.top/posts/flutter/channel/flutter-ios-spec-edit/ translation finally loaded. I believe the issue that's being reported is that an indexing bug in AppCode is getting triggered when embedding plugins via CocoaPods via add-to-app. However both that blog post and that issue are showing symlinking from plugin example apps up to their plugin. I'm not sure how symlinking the directory for add-to-app would be a problem (it's not walking up the tree from the example app to the plugin in the same way).

Can we get better reproduction steps?

You are free to create your own little Ruby helper to load in your host app Podfile if some other way to parse plugins works for you.

krmao commented 4 years ago

Hi @jmagman 👍 Thank you for reply !

The problem detail is here https://youtrack.jetbrains.com/issue/OC-17593

please see the detail comment

  • https://youtrack.jetbrains.com/issue/OC-17593#focus=streamItem-27-3032095.0-0
    The problem is that the generated Pods project has references 6 levels up, all the way up to the ~ folder (see Development Pods/flutter_credit_card_dongle/.. and Development Pods/flutter_scan_bluetooth/..). This results in AppCode trying to index the entire home folder. Could you please try to edit these generated references to something less crazy and see if it helps?
krmao commented 4 years ago

OK, may be the key is it's OK to access these folders using relative paths, but this should be done using only one reference like ../../../dir, not 4 references: .., .., .., dir.

I can finally use Xcode not AppCode, the issue I commit is a hope that flutter can used with 'add to app' by AppCode without any problems.

Well, this bug is created by AppCode, not flutter, And it's not necessary to compat AppCode.

Thank you again, I will close the issue.

stigger commented 4 years ago

Well, this bug is created by AppCode, not flutter

Both AppCode and Flutter contribute to the issue: both have a certain specific behavior, and when combined, it leads to an attempt to index the entire home folder.

To me, it looks like it's easier to fix on a Flutter side. The only thing we can do in AppCode is to try to recognise this specific scenario and handle it somehow.

And it's not necessary to compat AppCode

Still, our users are regularly stumbling upon this problem, so it would be nice to resolve it. Is there any specific reason why the generated Xcode project ends up with the references to the folders all the way up to the home directory?

krmao commented 4 years ago

@jmagman anything about this issue?

liushuai42 commented 4 years ago

How to hack for flutter 1.20

the podhelper.rb was moved to $FLUTTER_HOME

diff --git a/packages/flutter_tools/bin/podhelper.rb b/packages/flutter_tools/bin/podhelper.rb
index 9999ab9020..fc9e9d9d9f 100644
--- a/packages/flutter_tools/bin/podhelper.rb
+++ b/packages/flutter_tools/bin/podhelper.rb
@@ -117,7 +117,7 @@ def flutter_install_ios_plugin_pods(ios_application_path = nil)
       File.symlink(plugin_path, symlink)

       # Keep pod path relative so it can be checked into Podfile.lock.
-      pod plugin_name, :path => File.join('.symlinks', 'plugins', plugin_name, 'ios')
+      pod plugin_name, :path => "#{plugin_path}ios/#{plugin_name}.podspec"
     end
   end
 end
albemala commented 3 years ago

Any news regarding this issue?