Last active
August 29, 2023 14:31
-
-
Save android10/0b291129b4aec15b262d603612499e37 to your computer and use it in GitHub Desktop.
Compile and launch android app from the command line.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
task deployDebug(type: Exec, dependsOn: 'app:installDebug') { | |
def rootDir = project.rootDir | |
def localProperties = new File(rootDir, "local.properties") | |
if (localProperties.exists()) { | |
Properties properties = new Properties() | |
localProperties.withInputStream { | |
inputStream -> properties.load(inputStream) | |
} | |
def sdkDir = properties.getProperty('sdk.dir') | |
def adb = "$sdkDir/platform-tools/adb" | |
commandLine "$adb", 'shell', 'am', 'start', '-n', 'com.package/com.package.YourMainActivity' | |
} | |
} |
Instead of doing all this $adb
parsing, you can write
commandLine android.getAdbExe(), 'shell', 'am', 'start', '-n', "${android.defaultConfig.applicationId}/.MainActivity"
@whoww the problem is that if you have a project with multiple modules.
My solution is for the main build.gradle file where you do not have any android plugin get the adb location. 😄
task start(type: Exec) {
dependsOn 'installDebug'
commandLine 'adb', 'shell', 'am', 'start', '-n', "$android.defaultConfig.applicationId/.MainActivity"
}
@jlobos thanks!!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can also create a Gradle run configuration on Android Studio/Intellij.