Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I set path for my Shell Script in Android Studio?

I want to set Script Path for my script in android project without using a strict path(/User/Documents/MyApp/tools/script.sh) as well as "Working directory".

I know that I can use "External tools" but this solution doesn't work because all project developers will have to import my jar file with "external tools" settings

Can I somehow write this path using $ProjectFileDir$ variables? enter image description here

like image 767
serg3z Avatar asked Sep 17 '20 11:09

serg3z


People also ask

What is Android_home path?

Variable name: ANDROID_HOME , Variable value: the path where you installed the android SDK, in my case is, C:\Android\android-sdk . You have to add the variable to the Path variable system by adding this: ;%ANDROID_HOME%\platform-tools;%ANDROID_HOME%\tools; .

Can shell script run on Android?

It provides access to the Android file system and allows you to run Android applications from the command line. The Android shell is based on the Linux shell and provides many of the same commands. However, there are some important differences. The Android shell is not a full-fledged Linux environment.

How do I use Android Studio in a shell script?

To use it in your shell, you can add it to your .profile file: Please open a fresh terminal window after you did that, or load the changes by typing this in your terminal: Show activity on this post. Once you have Android Studio set up make sure you can connect to an emulator or a device where it will be listed in the AVD (Android Virtual Devices).

How to add terminal to path in Android Studio?

It's possible to add to PATH in Windows and use Terminal inside Android Studio only by command: adb shell and after use su get root shell. Older Windows will maybe need to reboot after changing the PATH variables.

How do I run a shell script from the path?

But on top of that, the PATH will be different in different contexts. For example, open the Script Editor application, make a new script document, enter do shell script "echo $PATH" and run the script by hitting the run/play button. The small AppleScript we just built runs the shell command echo from the AppleScript context.

How do I Find my Device's shell in Android Studio?

1 Access the terminal at the bottom of the IDE by selecting the Terminal button. 2 In the terminal issue adb devices. This will list the all devices currently connected to Android Studio. Find and use your device's name for step 3. 3 Now issue adb -s <device-name> shell. Now you are in your device's shell.


Video Answer


1 Answers

As of now, there is no direct way to use these variables in the path values of configurations.

Alternatively, you can create a gradle task in app/gradle file to run your shell scripts:

task runSS {
    doLast{
        exec {
            // chmod u+rwx demo.sh to make file executable
            executable "../demo.sh"
        }
    }
}

// other gradle tasks

Make sure to change the permission of the file to executable by using chmod u+rwx file_name.

Now run the file:

enter image description here

Output:

enter image description here

like image 192
Pavneet_Singh Avatar answered Nov 09 '22 16:11

Pavneet_Singh