Build Android Studio app via command line

后端 未结 12 1712
梦谈多话
梦谈多话 2020-11-27 10:36

I want to build an Android Studio app (the Gradle build system), but I want to do this via the command line.

相关标签:
12条回答
  • 2020-11-27 11:24

    Cheatsheet for running Gradle from the command line for Android Studio projects on Linux:

    cd <project-root>
    ./gradlew
    ./gradlew tasks
    ./gradlew --help
    

    Should get you started..

    0 讨论(0)
  • 2020-11-27 11:25

    there are two build types to build your application using the Gradle build settings: one for debugging your application — debug — and one for building your final package for release — release mode.

    Building in Debug Mode

    • First Navigate to Android studio project Root folder using CMD

    • run this command gradlew.bat assembleDebug

    • Output window look like this

    Build signed apk in Release Mode

    • Edit the build.gradle file to build your project in release mode:

      android {
      ...
      defaultConfig { ... }
      signingConfigs {
          release {
              storeFile file("myreleasekey.keystore")
              storePassword "password"
              keyAlias "MyReleaseKey"
              keyPassword "password"
          }
      }
      buildTypes {
          release {
              ...
              signingConfig signingConfigs.release
          }
      }}
      

    • run this command gradlew.bat assembleRelease

    Done.Good Luck!

    0 讨论(0)
  • 2020-11-27 11:27

    Try this (OS X only):

    brew install homebrew/versions/gradle110
    gradle build

    You can use gradle tasks to see all tasks available for the current project. No Android Studio is needed here.

    0 讨论(0)
  • 2020-11-27 11:30

    Official Documentation is here:

    To build a debug APK, open a command line and navigate to the root of your project directory. To initiate a debug build, invoke the assembleDebug task:

    gradlew assembleDebug
    

    This creates an APK named module_name-debug.apk in project_name/module_name/build/outputs/apk/.

    0 讨论(0)
  • 2020-11-27 11:31

    enter code hereCreate script file with below gradle and adb command, Execute script file

    ./gradlew clean
    

    ./gradlew assembleDebug ./gradlew installDebug

    adb shell am start -n applicationID/full path of launcher activity

    0 讨论(0)
  • 2020-11-27 11:32

    Only for MAC Users

    Extending Vji's answer.

    Step by step procedure:

    1. Open Terminal
    2. Change your directory to your Project(cd PathOfYourProject)
    3. Copy and paste this command and hit enter:

      chmod +x gradlew
      
    4. As Vji suggested:

      ./gradlew task-name
      

      DON'T FORGOT TO ADD .(DOT) BEFORE /gradlew

    0 讨论(0)
提交回复
热议问题