Itai Ganot
Itai Ganot

Reputation: 6305

How to install a large number of android-sdk tools and automatically accept their licenses?

I'm trying to automate the process of installing some Android SDK tools through a Gradle script.

The idea is to run this build.gradle script within a Docker machine which will prepare the environment before issuing the main build itself.

The problem I'm having is with automatically accepting the licenses for the relevant packages i'm installing.

Following this SO question, I'm trying to use this method:

echo "y" | android update sdk -u -a -t 2,4,56,57,58

If I run it in terminal it works for up to 6 packages in one command but if I want to install more packages than that, for example:

echo "y" | android update sdk -u -a -t 2,6,7,4,30,153,160,161,167,54,53,63,56,57,58,59

Then the command fails:

Do you accept the license 'intel-android-extra-license-3626590a' [y/n]:
Unknown response ''.
Do you accept the license 'intel-android-extra-license-3626590a' [y/n]:
Unknown response ''.
Max number of retries exceeded. Rejecting 'intel-android-extra-license-3626590a'
Package Android TV Intel x86 Atom System Image, Android API 24, revision 6 not installed due to rejected license 'android-sdk-preview-license-d099d938'.
Package Android Wear ARM EABI v7a System Image, Android API 24, revision 1 not installed due to rejected license 'android-sdk-preview-license-d099d938'.
Package ARM 64 v8a System Image, Android API 24, revision 6 not installed due to rejected license 'android-sdk-preview-license-d099d938'.

More than that, I need Gradle to run it for me and when I do so, it seems like the output of the first echo (echo "y") is not redirected to the pipe for some reason.

So when I run the relevant Gradle task:

12:46:01.178 [DEBUG] [org.gradle.process.internal.DefaultExecHandle] Changing state to: STARTING
12:46:01.179 [DEBUG] [org.gradle.process.internal.DefaultExecHandle] Waiting until process started: command '/bin/echo'.
12:46:01.183 [DEBUG] [org.gradle.process.internal.DefaultExecHandle] Changing state to: STARTED
12:46:01.183 [DEBUG] [org.gradle.process.internal.ExecHandleRunner] waiting until streams are handled...
12:46:01.183 [INFO] [org.gradle.process.internal.DefaultExecHandle] Successfully started process 'command '/bin/echo''
12:46:01.184 [QUIET] [system.out] y | /usr/local/bin/android  update  sdk  -u -a -t 2,6,7,4,30,153,160,161,167,54,53,63,56,57,58,59
12:46:01.184 [DEBUG] [org.gradle.process.internal.DefaultExecHandle] Changing state to: SUCCEEDED
12:46:01.185 [DEBUG] [org.gradle.process.internal.DefaultExecHandle] Process 'command '/bin/echo'' finished with exit value 0 (state: SUCCEEDED)
12:46:01.185 [DEBUG] [org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter] Finished executing task ':installSdkBuildTools'
12:46:01.185 [INFO] [org.gradle.execution.taskgraph.AbstractTaskPlanExecutor] :installSdkBuildTools (Thread[main,5,main]) completed. Took 0.023 secs.
12:46:01.185 [DEBUG] [org.gradle.execution.taskgraph.AbstractTaskPlanExecutor] Task worker [Thread[main,5,main]] finished, busy: 0.023 secs, idle: 0.001 secs
12:46:01.185 [DEBUG] [org.gradle.execution.taskgraph.DefaultTaskGraphExecuter] Timing: Executing the DAG took 0.044 secs
12:46:01.185 [LIFECYCLE] [org.gradle.BuildResultLogger]
12:46:01.186 [LIFECYCLE] [org.gradle.BuildResultLogger] BUILD SUCCESSFUL

The echo command ends successfully with exit status 0 but the packages are not being installed.

I've tried breaking the command to 3 mini commands which will install 6 packages each time but then the echo "y" | android... command is not interpreted correctly as mentioned above.

The relevant Gradle task looks like so:

task installSdkBuildToolsPart2(type: Exec) {
commandLine '/bin/echo', "y", '|', '/usr/local/bin/android ', 'update ', 'sdk ', '-u -a -t 160,161,167,54,53'
}

And I've also tried like that but to no avail:

task installSdkBuildToolsPart1(type: Exec) {
  commandLine 'bash', '-c'," '/bin/echo', "y", '|', '/usr/local/bin/android ', 'update ', 'sdk ', '-u -a -t 2,6,7,4,30,153'"
}

This is a Gradle question... how should I write the commandLine directive in the build.gradle file correctly so that the command is interpreted correctly and the packages are installed and licenses are accepted?

Anyone knows how to overcome this issue?

Thanks in advance,

Upvotes: 1

Views: 321

Answers (2)

zmarties
zmarties

Reputation: 4859

Your problem is that the exec task in Gradle does not know about pipes, so what you have written is simply passing a number of strings to echo; the "y", the pipe "|", the android path, the update command, etc.

One way to do this is to put the command you want to execute that contains pipes or other shell redirections characters into a shell script file, and then have the Gradle task exec that shell script.

Upvotes: 1

Geralt_Encore
Geralt_Encore

Reputation: 3771

We have this command, which works perfectly for us:

( sleep 5 && while [ 1 ]; do sleep 1; echo y; done ) \
| android update sdk --all -u -t

Upvotes: 0

Related Questions