Skip to content

Support release builds from CLI #324

Closed

Description

@mlynch

We will need to do CI/Cloud builds for apps in Ionic, should we support running xcodebuild/gradle easily from the CLI?

npx cap build

Activity

  1. jcesarmobile commented on Mar 13, 2018

    @jcesarmobile
    Member

    Is the CI something we control? we can configure the CI to build the native project

  2. mlynch commented on Mar 13, 2018

    @mlynch
    ContributorAuthor

    Yea, but just CI's in general, we could make it easier to build the app from the command line

  3. janpio commented on Mar 15, 2018

    @janpio
    Contributor

    fastlane has very good build support for both Android and iOS - maybe this could be an alternative? (With build come profiles, certificates, output paths...)

  4. zarko-tg commented on Nov 21, 2018

    @zarko-tg

    Major showstopper for us as we've almost never had to open/use any IDE, having a well functioning build/release setup/process via command line.

  5. ptitjes commented on Nov 21, 2018

    @ptitjes
    Contributor

    @zarko-tg You can do (cd android/ && ./gradlew assembleRelease) for Android.
    See for instance:

    You can do something like xcodebuild -scheme App build for iOS.
    But I can't tell exactly as I didn't pay Apple's dime yet.

  6. wilsolutions commented on Dec 6, 2018

    @wilsolutions

    Hi, I've tried the steps above for Android, it did generate the expected .apk file however if fails when I try to install in the device.
    This is the error message that I got from logcat:
    com.google.android.packageinstaller/com.android.packageinstaller.InstallFailed (has extras)

    • iOS:
      xcodebuild -workspace App.xcworkspace -scheme App clean archive -configuration debug -sdk iphoneos -archivePath App.xcarchive

    It fails with:
    AppDelegate.swift:2:8: error: no such module 'Capacitor'

    Any thoughts about it?
    tkx

  7. jcesarmobile commented on Dec 6, 2018

    @jcesarmobile
    Member

    Did you run it from ios/App/ folder?

    I just copy/pasted your command in one random Capacitor project and worked fine

    You can also try to run pod install from ios/App/ first, but shouldn't be necessary as npx cap update ios already run it

  8. wilsolutions commented on Dec 6, 2018

    @wilsolutions

    Hola @jcesarmobile, thank you for the feedback.
    Yes, I did run from the ios/App folder.

    From the ios/App:

    1. ✗ pod install
      Ignoring nokogiri-1.8.4 because its extensions are not built. Try: gem pristine nokogiri --version 1.8.4
      Ignoring unf_ext-0.0.7.5 because its extensions are not built. Try: gem pristine unf_ext --version 0.0.7.5
      Analyzing dependencies
      Fetching podspec for Capacitor from ../../node_modules/@capacitor/ios
      Fetching podspec for CapacitorCordova from ../../node_modules/@capacitor/ios
      Fetching podspec for CordovaPlugins from ../capacitor-cordova-ios-plugins
      Downloading dependencies
      Using Capacitor (1.0.0-beta.7)
      Using CapacitorCordova (1.0.0-beta.7)
      Using CordovaPlugins (1.0.0-beta.11)
      Using GCDWebServer (3.4.2)
      Generating Pods project
      Integrating client project
      Sending stats
      Pod installation complete! There are 3 dependencies from the Podfile and 4 total pods installed.

    2. ✗ xcodebuild -workspace App.xcworkspace -scheme App clean archive -configuration debug -sdk iphoneos -archivePath App.xcarchive

    AppDelegate.swift:2:8: error: no such module 'Capacitor'
    import Capacitor
    ^
    ** ARCHIVE FAILED **
    The following build commands failed:
    CompileSwift normal armv7 /Users/wils/_work/projects/prototype01/ios/App/App/AppDelegate.swift
    CompileSwiftSources normal arm64 com.apple.xcode.tools.swift.compiler
    CompileSwift normal arm64 /Users/wils/_work/projects/prototype01/ios/App/App/AppDelegate.swift
    (3 failures)

    tkx

  9. wilsolutions commented on Dec 6, 2018

    @wilsolutions

    It works!

    I have just created a new project and it works!

    So, looks likes some discrepancy in my previous project, after reading jcesarmobile message I decided to create a new project and voilà!

    tkx

  10. Rodrigo54 commented on Mar 28, 2019

    @Rodrigo54

    consider using @bazelbuild to compile for ios, android and electron
    it would be better to centralize everything in a single tool instead of worrying about Gradle and CocoaPods

  11. Coly010 commented on Mar 20, 2020

    @Coly010
  12. Heerschop commented on Apr 26, 2020

    @Heerschop
    Contributor

    I have created a pull request #4403 to make the open of the development IDE optional. This will help using ionic capacitor from the CLI, especially when you what to use the --livereload option.

    Currently, if you what to use live reload from the CLI. You can not use the ionic capacitor run <platform> --livereload command, because it will always start the corresponding IDE. So you have to write custom scripts that will update the capacitor.config.json file with the correct information needed for live reload to work. The pull request can make this use case simpler.

  13. Heerschop commented on Apr 30, 2020

    @Heerschop
    Contributor

    The pull request #4403 has just been merged. As of version 6.7.0 of the Ionic CLI, you can use the --no-open option for the ionic capacitor run and ionic capacitor build command.

  14. 9 remaining items

  15. jcesarmobile commented on Aug 17, 2020

    @jcesarmobile
    Member

    What docs are you referring to?
    Capacitor docs don't tell you to use Cordova anywhere.

    Capacitor doesn't support building from the CLI at the moment, you have to use gradle on Android or xcodebuild on iOS (or some multi platform tool such as fastlane)

  16. infacto commented on Aug 26, 2020

    @infacto

    Capacitor should primary build on CLI (e.g. Android SDK Tools, without Android Studio IDE). The current behavior is not CI friendly. Not even for humans. Why? 😢 It's a pain. I read something about Capacitor is not for release builds. Oo Then what is it for? It sounds like a joke.

  17. imhoffd commented on Aug 26, 2020

    @imhoffd
    Contributor

    Let's keep things constructive in accordance with our Code of Conduct.

    Then what is it for?

    Capacitor is first and foremost a cross-platform native runtime for web apps. The primary purpose is to provide a translation layer from web app to native platform. One of the philosophical differences between Capacitor and Cordova is that Capacitor doesn't try to abstract away the native platforms, it embraces them. The platforms in Capacitor projects are true native projects and considered source artifacts, not build artifacts. They're as much a part of your app as the JS you write.

    You're encouraged to use Gradle for Android and xcodebuild for iOS in the command-line and CI environments because they're the official tools provided by Android and iOS. Third-party tools such as Fastlane may make this easier. Fastlane has been around much longer than Capacitor and has 20+ members on its core team alone. It's better if Capacitor focuses on its unique strengths instead of reinventing the wheel.

    Could we document this better? Absolutely. Capacitor is just getting started.

  18. Siedlerchr commented on Sep 8, 2020

    @Siedlerchr

    I understand your argument, but only partly, even if you say use xcodebuild or gradle, why don't use the Cordova approach and pass the parameters for building down to the nativettools ?
    Even java just passes the parameters down to the native build tools for packaging and signing apps with the jpackage tool.

  19. Heerschop commented on Nov 20, 2020

    @Heerschop
    Contributor

    This Ionic Capacitor example project can be used for building with Capacitor from the CLI. The project uses ionic hooks and script-launcher for enabling this.

    For Android, it should just work as long as you have Android Studio installed and setup. For Apple, you first have to make sure you have configured your certificates and provisioning profiles accordingly, and then update the export-store-options.plist and export-debug-options.plist files as explained in the README.

    When all Android and iOS dependencies are correctly setup, then a CLI build can be started by using the native ionic capacitor commands like:

    # Build Android debug apk
    npx ionic capacitor build android --no-open
    
    # Build Android Production apk
    npx ionic capacitor build android --no-open --configuration=production
    
    # Run Android debug IPA with livereload
    adb reverse tcp:8100 tcp:8100
    npx ionic capacitor run android --no-open --livereload --port=8100
    
    # Build iOS debug IPA
    npx ionic capacitor build ios --no-open
    
    # Build iOS Production IPA
    npx ionic capacitor build ios --no-open --configuration=production
    
    # Run iOS debug IPA with livereload
    npx ionic capacitor run ios --no-open --livereload --external --port=8100

    Or you can use the menu by executing npm start to select and start the desired action interactively.

    npm start
    
    ? Select action › - Use arrow-keys. Return to submit.
    ❯   serve - Builds and serves your app, rebuilding on file changes.
        build
        deploy

    Hope this will help people to get started using ionic capacitors in a CI / CD environment.

  20. added
    needs investigation
    and removed on Dec 24, 2020
  21. tmk1991 commented on Jul 1, 2021

    @tmk1991

    @Heerschop - where does the build ios or build android output the app binary? Those commands seem to merely build your ionic application and not the binary.

    Once the web assets and configuration are copied into your native project, you can build your app using the native IDE. Unfortunately, programmatically building the native project is not yet supported.

    https://ionicframework.com/docs/cli/commands/capacitor-build

    @ptitjes answer above is the correct CLI way to build a native binary.

  22. Sampath-Lokuge commented on Aug 19, 2021

    @Sampath-Lokuge

    I think this is a MUST need feature now with Capacitor 3 CLI hence now we can open the app directly on our device without native tools. And the huge problem we have now is even though we'll build our app with --prod it doesn't reduce the bundle size when we use the Native tools. This is a huge problem right now for us for testing. i.e. first impression is very important here from our clients. i.e. giving high performance and small bundle size app to the client for testing using --prod.

    I have asked about it here also but no reply yet? #4754

  23. jcesarmobile commented on Nov 1, 2022

    @jcesarmobile
    Member
  24. ionitron-bot commented on Dec 1, 2022

    @ionitron-bot

    Thanks for the issue! This issue is being locked to prevent comments that are not relevant to the original issue. If this is still an issue with the latest version of Capacitor, please create a new issue and ensure the template is fully filled out.

  25. locked and limited conversation to collaborators on Dec 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    clienhancementneeds investigation

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions