Cordova: Correct way to add plugin configuration and resources?



.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








3















Cordova project. Firebase plugin (custom plugin). I am trying to figure out what the correct way to specify custom resource details that a plugin will use when the platform or plugin is added.



For instance, API_KEY, APP_ID and google-service.json for android, and GoogleServices-Info.plist for iOS



I have API_KEY and APP_ID nailed I think in plugin.xml



<platform name="android">
<preference name="API_KEY"/>
<preference name="APP_ID"/>

<config-file parent="/resources" target="res/values/strings.xml">
<string name="google_app_id">$APP_ID</string>
<string name="google_api_key">$API_KEY</string>
</config-file>
</platform>


So when the plugin is added I do cordova plugin add myfirebaseplugin --variable APP_ID=blah --variable API_KEY=blah



But what I have not worked out yet is the correct way to install google-service.json or Google-Service.Info.plist



I have tried having --variable IOS_FIREBASE_CONFIG="<path>" and using <source-file src="$IOS_FIREBASE_CONFIG" target-dir="$PACKAGE_NAME/Resources"/> in plugin.xml but it seems source-file wont expand $IOS_FIREBASE_CONFIG.



".../plugins/firebase/$IOS_FIREBASE_CONFIG" not found!


Can the plugin handle the setup the config based on variables I pass in? Or is this (copying the config files) something config.xml would handle during platform add?



I have looked at a few firebase plugins and how they deal with it and it seems they cop out and tell you to manually copy in the config files into the platform folders, which doesn't feel right.



As a last resort I can probably write a hook for platform add.










share|improve this question






























    3















    Cordova project. Firebase plugin (custom plugin). I am trying to figure out what the correct way to specify custom resource details that a plugin will use when the platform or plugin is added.



    For instance, API_KEY, APP_ID and google-service.json for android, and GoogleServices-Info.plist for iOS



    I have API_KEY and APP_ID nailed I think in plugin.xml



    <platform name="android">
    <preference name="API_KEY"/>
    <preference name="APP_ID"/>

    <config-file parent="/resources" target="res/values/strings.xml">
    <string name="google_app_id">$APP_ID</string>
    <string name="google_api_key">$API_KEY</string>
    </config-file>
    </platform>


    So when the plugin is added I do cordova plugin add myfirebaseplugin --variable APP_ID=blah --variable API_KEY=blah



    But what I have not worked out yet is the correct way to install google-service.json or Google-Service.Info.plist



    I have tried having --variable IOS_FIREBASE_CONFIG="<path>" and using <source-file src="$IOS_FIREBASE_CONFIG" target-dir="$PACKAGE_NAME/Resources"/> in plugin.xml but it seems source-file wont expand $IOS_FIREBASE_CONFIG.



    ".../plugins/firebase/$IOS_FIREBASE_CONFIG" not found!


    Can the plugin handle the setup the config based on variables I pass in? Or is this (copying the config files) something config.xml would handle during platform add?



    I have looked at a few firebase plugins and how they deal with it and it seems they cop out and tell you to manually copy in the config files into the platform folders, which doesn't feel right.



    As a last resort I can probably write a hook for platform add.










    share|improve this question


























      3












      3








      3








      Cordova project. Firebase plugin (custom plugin). I am trying to figure out what the correct way to specify custom resource details that a plugin will use when the platform or plugin is added.



      For instance, API_KEY, APP_ID and google-service.json for android, and GoogleServices-Info.plist for iOS



      I have API_KEY and APP_ID nailed I think in plugin.xml



      <platform name="android">
      <preference name="API_KEY"/>
      <preference name="APP_ID"/>

      <config-file parent="/resources" target="res/values/strings.xml">
      <string name="google_app_id">$APP_ID</string>
      <string name="google_api_key">$API_KEY</string>
      </config-file>
      </platform>


      So when the plugin is added I do cordova plugin add myfirebaseplugin --variable APP_ID=blah --variable API_KEY=blah



      But what I have not worked out yet is the correct way to install google-service.json or Google-Service.Info.plist



      I have tried having --variable IOS_FIREBASE_CONFIG="<path>" and using <source-file src="$IOS_FIREBASE_CONFIG" target-dir="$PACKAGE_NAME/Resources"/> in plugin.xml but it seems source-file wont expand $IOS_FIREBASE_CONFIG.



      ".../plugins/firebase/$IOS_FIREBASE_CONFIG" not found!


      Can the plugin handle the setup the config based on variables I pass in? Or is this (copying the config files) something config.xml would handle during platform add?



      I have looked at a few firebase plugins and how they deal with it and it seems they cop out and tell you to manually copy in the config files into the platform folders, which doesn't feel right.



      As a last resort I can probably write a hook for platform add.










      share|improve this question
















      Cordova project. Firebase plugin (custom plugin). I am trying to figure out what the correct way to specify custom resource details that a plugin will use when the platform or plugin is added.



      For instance, API_KEY, APP_ID and google-service.json for android, and GoogleServices-Info.plist for iOS



      I have API_KEY and APP_ID nailed I think in plugin.xml



      <platform name="android">
      <preference name="API_KEY"/>
      <preference name="APP_ID"/>

      <config-file parent="/resources" target="res/values/strings.xml">
      <string name="google_app_id">$APP_ID</string>
      <string name="google_api_key">$API_KEY</string>
      </config-file>
      </platform>


      So when the plugin is added I do cordova plugin add myfirebaseplugin --variable APP_ID=blah --variable API_KEY=blah



      But what I have not worked out yet is the correct way to install google-service.json or Google-Service.Info.plist



      I have tried having --variable IOS_FIREBASE_CONFIG="<path>" and using <source-file src="$IOS_FIREBASE_CONFIG" target-dir="$PACKAGE_NAME/Resources"/> in plugin.xml but it seems source-file wont expand $IOS_FIREBASE_CONFIG.



      ".../plugins/firebase/$IOS_FIREBASE_CONFIG" not found!


      Can the plugin handle the setup the config based on variables I pass in? Or is this (copying the config files) something config.xml would handle during platform add?



      I have looked at a few firebase plugins and how they deal with it and it seems they cop out and tell you to manually copy in the config files into the platform folders, which doesn't feel right.



      As a last resort I can probably write a hook for platform add.







      cordova plugins






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Sep 27 '17 at 14:33







      Austin France

















      asked Sep 27 '17 at 14:20









      Austin FranceAustin France

      9121923




      9121923






















          1 Answer
          1






          active

          oldest

          votes


















          6














          If you are using Cordova CLI 7 you can use resource-file tag in the config.xml



          you don't have to do anything, just document it so the user put the file on the root of the project and adds this in the config.xml



          For cordova-android 6.x.x and older



          <platform name="android">
          <resource-file src="google-services.json" target="google-services.json" />
          </platform>


          For cordova-android 7.x.x



          <platform name="android">
          <resource-file src="google-services.json" target="app/google-services.json" />
          </platform>


          For iOS



          <platform name="ios">
          <resource-file src="GoogleService-Info.plist" />
          </platform>





          share|improve this answer

























          • This certainly works, thank you. I guess I was trying too hard getting the plugin.xml config to do it all (via a variable) instead of just going for the simpler option of doing it in config.xml

            – Austin France
            Sep 27 '17 at 16:41












          • why is it that iOS doesn't get a target? I don't see the file getting copied to the platform/ios folder like it does in android

            – Kenny Hammerlund
            Nov 15 '18 at 15:51











          • because iOS resources should go to Resources folder as that's where resources should be, but Android resources can go to different folders, so you need to tell which one with the target

            – jcesarmobile
            Nov 15 '18 at 16:00











          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f46450352%2fcordova-correct-way-to-add-plugin-configuration-and-resources%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          6














          If you are using Cordova CLI 7 you can use resource-file tag in the config.xml



          you don't have to do anything, just document it so the user put the file on the root of the project and adds this in the config.xml



          For cordova-android 6.x.x and older



          <platform name="android">
          <resource-file src="google-services.json" target="google-services.json" />
          </platform>


          For cordova-android 7.x.x



          <platform name="android">
          <resource-file src="google-services.json" target="app/google-services.json" />
          </platform>


          For iOS



          <platform name="ios">
          <resource-file src="GoogleService-Info.plist" />
          </platform>





          share|improve this answer

























          • This certainly works, thank you. I guess I was trying too hard getting the plugin.xml config to do it all (via a variable) instead of just going for the simpler option of doing it in config.xml

            – Austin France
            Sep 27 '17 at 16:41












          • why is it that iOS doesn't get a target? I don't see the file getting copied to the platform/ios folder like it does in android

            – Kenny Hammerlund
            Nov 15 '18 at 15:51











          • because iOS resources should go to Resources folder as that's where resources should be, but Android resources can go to different folders, so you need to tell which one with the target

            – jcesarmobile
            Nov 15 '18 at 16:00















          6














          If you are using Cordova CLI 7 you can use resource-file tag in the config.xml



          you don't have to do anything, just document it so the user put the file on the root of the project and adds this in the config.xml



          For cordova-android 6.x.x and older



          <platform name="android">
          <resource-file src="google-services.json" target="google-services.json" />
          </platform>


          For cordova-android 7.x.x



          <platform name="android">
          <resource-file src="google-services.json" target="app/google-services.json" />
          </platform>


          For iOS



          <platform name="ios">
          <resource-file src="GoogleService-Info.plist" />
          </platform>





          share|improve this answer

























          • This certainly works, thank you. I guess I was trying too hard getting the plugin.xml config to do it all (via a variable) instead of just going for the simpler option of doing it in config.xml

            – Austin France
            Sep 27 '17 at 16:41












          • why is it that iOS doesn't get a target? I don't see the file getting copied to the platform/ios folder like it does in android

            – Kenny Hammerlund
            Nov 15 '18 at 15:51











          • because iOS resources should go to Resources folder as that's where resources should be, but Android resources can go to different folders, so you need to tell which one with the target

            – jcesarmobile
            Nov 15 '18 at 16:00













          6












          6








          6







          If you are using Cordova CLI 7 you can use resource-file tag in the config.xml



          you don't have to do anything, just document it so the user put the file on the root of the project and adds this in the config.xml



          For cordova-android 6.x.x and older



          <platform name="android">
          <resource-file src="google-services.json" target="google-services.json" />
          </platform>


          For cordova-android 7.x.x



          <platform name="android">
          <resource-file src="google-services.json" target="app/google-services.json" />
          </platform>


          For iOS



          <platform name="ios">
          <resource-file src="GoogleService-Info.plist" />
          </platform>





          share|improve this answer















          If you are using Cordova CLI 7 you can use resource-file tag in the config.xml



          you don't have to do anything, just document it so the user put the file on the root of the project and adds this in the config.xml



          For cordova-android 6.x.x and older



          <platform name="android">
          <resource-file src="google-services.json" target="google-services.json" />
          </platform>


          For cordova-android 7.x.x



          <platform name="android">
          <resource-file src="google-services.json" target="app/google-services.json" />
          </platform>


          For iOS



          <platform name="ios">
          <resource-file src="GoogleService-Info.plist" />
          </platform>






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Nov 15 '18 at 16:01

























          answered Sep 27 '17 at 14:58









          jcesarmobilejcesarmobile

          37.3k782126




          37.3k782126












          • This certainly works, thank you. I guess I was trying too hard getting the plugin.xml config to do it all (via a variable) instead of just going for the simpler option of doing it in config.xml

            – Austin France
            Sep 27 '17 at 16:41












          • why is it that iOS doesn't get a target? I don't see the file getting copied to the platform/ios folder like it does in android

            – Kenny Hammerlund
            Nov 15 '18 at 15:51











          • because iOS resources should go to Resources folder as that's where resources should be, but Android resources can go to different folders, so you need to tell which one with the target

            – jcesarmobile
            Nov 15 '18 at 16:00

















          • This certainly works, thank you. I guess I was trying too hard getting the plugin.xml config to do it all (via a variable) instead of just going for the simpler option of doing it in config.xml

            – Austin France
            Sep 27 '17 at 16:41












          • why is it that iOS doesn't get a target? I don't see the file getting copied to the platform/ios folder like it does in android

            – Kenny Hammerlund
            Nov 15 '18 at 15:51











          • because iOS resources should go to Resources folder as that's where resources should be, but Android resources can go to different folders, so you need to tell which one with the target

            – jcesarmobile
            Nov 15 '18 at 16:00
















          This certainly works, thank you. I guess I was trying too hard getting the plugin.xml config to do it all (via a variable) instead of just going for the simpler option of doing it in config.xml

          – Austin France
          Sep 27 '17 at 16:41






          This certainly works, thank you. I guess I was trying too hard getting the plugin.xml config to do it all (via a variable) instead of just going for the simpler option of doing it in config.xml

          – Austin France
          Sep 27 '17 at 16:41














          why is it that iOS doesn't get a target? I don't see the file getting copied to the platform/ios folder like it does in android

          – Kenny Hammerlund
          Nov 15 '18 at 15:51





          why is it that iOS doesn't get a target? I don't see the file getting copied to the platform/ios folder like it does in android

          – Kenny Hammerlund
          Nov 15 '18 at 15:51













          because iOS resources should go to Resources folder as that's where resources should be, but Android resources can go to different folders, so you need to tell which one with the target

          – jcesarmobile
          Nov 15 '18 at 16:00





          because iOS resources should go to Resources folder as that's where resources should be, but Android resources can go to different folders, so you need to tell which one with the target

          – jcesarmobile
          Nov 15 '18 at 16:00



















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f46450352%2fcordova-correct-way-to-add-plugin-configuration-and-resources%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Use pre created SQLite database for Android project in kotlin

          Darth Vader #20

          Ondo