GNUGradyn / react-native-google-auth

Authentication and Authorization with Google for React Native
MIT License
0 stars 0 forks source link

Issues manually adding a module to this project #1

Open GNUGradyn opened 2 months ago

GNUGradyn commented 2 months ago

This library relies on the GoogleSignIn library from google. The problem is it uses functionality from a fork that has not been merged by Google yet, and .podspec files do not support specifying a git repo for a module like the actual Podfile does. To circumvent this issue I opted to clone the fork into this libraries source code and treat it as a sort of submodule. I setup the public_header_files/private_header_files/resource_bundle properties in the podspec based on the GoogleSignIn submodules podspec and added the headers to my HEADER_SEARCH_PATHS. I then added the public headers to the bridging header.

So in the podspec I have

  s.source_files = "ios/**/*.{h,m,mm,swift}", "GoogleSignIn-iOS/GoogleSignIn/Sources/**/*.{h,m,mm,swift}"
  s.public_header_files = "GoogleSignIn-iOS/GoogleSignIn/Sources/Public/GoogleSignIn/*.h"
  s.private_header_files = "GoogleSignIn-iOS/GoogleSignIn/Sources/**/*.h"

  s.resource_bundle = {
    'GoogleSignIn' => ['GoogleSignIn-iOS/GoogleSignIn/Sources/{Resources,Strings}/*']
  }

  s.pod_target_xcconfig = {
    'HEADER_SEARCH_PATHS' => '"$(inherited)" "$(PODS_ROOT)/GoogleSignIn-iOS/GoogleSignIn/Sources/Public/GoogleSignIn" "$(PODS_ROOT)/GoogleSignIn-iOS/GoogleSignIn/Sources"'
  }

  s.user_target_xcconfig = {
    'HEADER_SEARCH_PATHS' => '"$(inherited)" "$(PODS_ROOT)/GoogleSignIn-iOS/GoogleSignIn/Sources/Public/GoogleSignIn" "$(PODS_ROOT)/GoogleSignIn-iOS/GoogleSignIn/Sources"'
  }

and in the bridging header

#import "GIDAppCheckError.h"
#import "GIDConfiguration.h"
#import "GIDGoogleUser.h"
#import "GIDProfileData.h"
#import "GIDSignIn.h"
#import "GIDSignInButton.h"
#import "GIDSignInResult.h"
#import "GIDToken.h"
#import "GoogleSignIn.h"

This is working to some extent because I can see the headers in the pod project image Not sure why they're under project but I manually moved them to private/public and it didn't seem to affect anything.

Anyway regardless which category I put the headers in, I cannot actually import GoogleSignIn from outside the "submodule". imageAdditionally, some files within the "submodule" cannot find each other. For example at GoogleSignIn-iOS/GoogleSignIn/Sources/GIDToken.m I have #import "GoogleSignIn/Sources/Public/GoogleSignIn/GIDToken.h", which just results in 'GoogleSignIn/Sources/Public/GoogleSignIn/GIDToken.h' file not found. If I just do #import "GIDToken.h" its fine but I can't actually rewrite the imports otherwise they'll break again when I update the submodule from git. I have asked on several Discord communites as well as ChatGPT but I cannot find any configuration that makes this submodule work via the podspec.

DOUINA-Mouhamed commented 1 month ago

Hello (issue found on discord: f143mg, on server TCD)

Try to change the podspec:

require "json"

package = JSON.parse(File.read(File.join(__dir__, "package.json")))
folly_compiler_flags = '-DFOLLY_NO_CONFIG -DFOLLY_MOBILE=1 -DFOLLY_USE_LIBCPP=1 -Wno-comma -Wno-shorten-64-to-32'

Pod::Spec.new do |s|
  s.name         = "react-native-google-auth"
  s.version      = package["version"]
  s.summary      = package["description"]
  s.homepage     = package["homepage"]
  s.license      = package["license"]
  s.authors      = package["author"]

  s.platforms    = { :ios => "10.0" }
  s.source       = { :git => "https://github.com/GNUGradyn/react-native-google-auth.git", :tag => s.version.to_s }

  s.source_files = "ios/**/*.{h,m,mm,swift}", "GoogleSignIn-iOS/GoogleSignIn/Sources/**/*.{h,m,mm,swift}"
  s.public_header_files = "GoogleSignIn-iOS/GoogleSignIn/Sources/Public/GoogleSignIn/*.h"
  s.private_header_files = "GoogleSignIn-iOS/GoogleSignIn/Sources/**/*.h"
  s.resource_bundles = {
    'GoogleSignIn' => ['GoogleSignIn-iOS/GoogleSignIn/Sources/{Resources,Strings}/*']
  }

  s.pod_target_xcconfig = {
    "HEADER_SEARCH_PATHS" => "\"$(PODS_ROOT)/GoogleSignIn-iOS/GoogleSignIn/Sources/Public/GoogleSignIn\" \"$(PODS_ROOT)/GoogleSignIn-iOS/GoogleSignIn/Sources\"",
    "OTHER_CPLUSPLUSFLAGS" => folly_compiler_flags,
    "CLANG_CXX_LANGUAGE_STANDARD" => "c++17"
  }

  s.user_target_xcconfig = {
    "HEADER_SEARCH_PATHS" => "\"$(PODS_ROOT)/GoogleSignIn-iOS/GoogleSignIn/Sources/Public/GoogleSignIn\" \"$(PODS_ROOT)/GoogleSignIn-iOS/GoogleSignIn/Sources\""
  }

  # dependencies for React Native
  if respond_to?(:install_modules_dependencies, true)
    install_modules_dependencies(s)
  else
    s.dependency "React-Core"

    # additional dependencies and configurations for the new architecture
    if ENV['RCT_NEW_ARCH_ENABLED'] == '1' then
      s.compiler_flags = folly_compiler_flags + " -DRCT_NEW_ARCH_ENABLED=1"
      s.pod_target_xcconfig.merge!({
        "HEADER_SEARCH_PATHS" => "\"$(PODS_ROOT)/boost\"",
        "OTHER_CPLUSPLUSFLAGS" => folly_compiler_flags,
        "CLANG_CXX_LANGUAGE_STANDARD" => "c++17"
      })
      s.dependency "React-Codegen"
      s.dependency "RCT-Folly"
      s.dependency "RCTRequired"
      s.dependency "RCTTypeSafety"
      s.dependency "ReactCommon/turbomodule/core"
    end
  end
end

And check GID header:

#import "GIDAppCheckError.h"
#import "GIDConfiguration.h"
#import "GIDGoogleUser.h"
#import "GIDProfileData.h"
#import "GIDSignIn.h"
#import "GIDSignInButton.h"
#import "GIDSignInResult.h"
#import "GIDToken.h"
GNUGradyn commented 1 month ago

@DOUINA-Mouhamed no dice. #import "GoogleSignIn/Sources/NSBundle+GID3PAdditions.h" still has to be rewritten as NSBundle+GID3PAdditions.h" for example. also where is this GID header file you're referring to

DOUINA-Mouhamed commented 1 month ago

I was talking about bridging header.

Try writing your podspec file like this :

require "json"

package = JSON.parse(File.read(File.join(__dir__, "package.json")))
folly_compiler_flags = '-DFOLLY_NO_CONFIG -DFOLLY_MOBILE=1 -DFOLLY_USE_LIBCPP=1 -Wno-comma -Wno-shorten-64-to-32'

Pod::Spec.new do |s|
  s.name         = "react-native-google-auth"
  s.version      = package["version"]
  s.summary      = package["description"]
  s.homepage     = package["homepage"]
  s.license      = package["license"]
  s.authors      = package["author"]

  s.platforms    = { :ios => "10.0" }
  s.source       = { :git => "https://github.com/GNUGradyn/react-native-google-auth.git", :tag => s.version.to_s }

  s.source_files = "ios/**/*.{h,m,mm,swift}", "GoogleSignIn-iOS/GoogleSignIn/Sources/**/*.{h,m,mm,swift}"
  s.public_header_files = "GoogleSignIn-iOS/GoogleSignIn/Sources/Public/GoogleSignIn/*.h"
  s.private_header_files = "GoogleSignIn-iOS/GoogleSignIn/Sources/**/*.h"

  s.resource_bundles = {
    'GoogleSignIn' => ['GoogleSignIn-iOS/GoogleSignIn/Sources/{Resources,Strings}/*']
  }

  s.pod_target_xcconfig = {
    "HEADER_SEARCH_PATHS" => "\"$(PODS_ROOT)/GoogleSignIn-iOS/GoogleSignIn/Sources/Public/GoogleSignIn\" \"$(PODS_ROOT)/GoogleSignIn-iOS/GoogleSignIn/Sources\"",
    "OTHER_CPLUSPLUSFLAGS" => folly_compiler_flags,
    "CLANG_CXX_LANGUAGE_STANDARD" => "c++17"
  }
  s.user_target_xcconfig = {
    "HEADER_SEARCH_PATHS" => "\"$(PODS_ROOT)/GoogleSignIn-iOS/GoogleSignIn/Sources/Public/GoogleSignIn\" \"$(PODS_ROOT)/GoogleSignIn-iOS/GoogleSignIn/Sources\""
  }

  s.module_name = 'GoogleSignIn'
  s.module_map = 'GoogleSignIn-iOS/GoogleSignIn/module.modulemap'

  if respond_to?(:install_modules_dependencies, true)
    install_modules_dependencies(s)
  else
    s.dependency "React-Core"

    if ENV['RCT_NEW_ARCH_ENABLED'] == '1' then
      s.compiler_flags = folly_compiler_flags + " -DRCT_NEW_ARCH_ENABLED=1"
      s.pod_target_xcconfig.merge!({
        "HEADER_SEARCH_PATHS" => "\"$(PODS_ROOT)/boost\"",
        "OTHER_CPLUSPLUSFLAGS" => folly_compiler_flags,
        "CLANG_CXX_LANGUAGE_STANDARD" => "c++17"
      })
      s.dependency "React-Codegen"
      s.dependency "RCT-Folly"
      s.dependency "RCTRequired"
      s.dependency "RCTTypeSafety"
      s.dependency "ReactCommon/turbomodule/core"
    end
  end
end

Create a module.modulemap file in GoogleSignIn folder:

module GoogleSignIn {
  header "GIDAppCheckError.h"
  header "GIDConfiguration.h"
  header "GIDGoogleUser.h"
  header "GIDProfileData.h"
  header "GIDSignIn.h"
  header "GIDSignInButton.h"
  header "GIDSignInResult.h"
  header "GIDToken.h"
  export *
}

Then to make sure:

rm -rf Pods/
pod cache clean --all
pod install

Double check the bridging imports.

GNUGradyn commented 1 month ago

[!] Using Swift static libraries with custom module maps is currently not supported. Please build react-native-google-auth as a framework or remove the custom module map. Also I'm pretty sure the paths in the module map you provided are wrong anyway.. are you testing these solutions?

DOUINA-Mouhamed commented 1 month ago

I can't directly test the integration of iOS dependencies like GoogleSignIn because I do not own a Mac, I do not have a macOS VM and I don't have time to set up one sadly...