Search code examples
androidunixcommand-lineant

ant build error "java.lang.RuntimeException: The executable 'android' is not in the path"


I am trying to build an Android app instrumenting tool called Ella from https://github.com/saswatanand/ella

When I was trying to build it using ant, it shows this error:

Buildfile: /Users/sioyoo/tools/ella/build.xml

create-keystore:

init:

build:

init:
    [mkdir] Created dir: /Users/sioyoo/tools/ella/instrument/build

compile:
    [javac] Compiling 67 source files to /Users/sioyoo/tools/ella/instrument/build
    [javac] Note: /Users/sioyoo/tools/ella/instrument/src/com/apposcopy/ella/Instrument.java uses or overrides a deprecated API.
    [javac] Note: Recompile with -Xlint:deprecation for details.
    [javac] Note: Some input files use unchecked or unsafe operations.
    [javac] Note: Recompile with -Xlint:unchecked for details.

jar:
      [zip] Building zip: /Users/sioyoo/tools/ella/bin/ella.instrument.jar

init:
    [mkdir] Created dir: /Users/sioyoo/tools/ella/runtime/build
    [javac] /Users/sioyoo/tools/ella/runtime/build.xml:15: warning: 'includeantruntime' was not set, defaulting to build.sysclasspath=last; set to false for repeatable builds
    [javac] Compiling 1 source file to /Users/sioyoo/tools/ella/runtime

BUILD FAILED
/Users/sioyoo/tools/ella/build.xml:49: The following error occurred while executing this line:
/Users/sioyoo/tools/ella/runtime/build.xml:21: java.lang.RuntimeException: The executable 'android' is not in the path
    at GuessDefaultSettingsTask.findAndroidSDKPath(GuessDefaultSettingsTask.java:46)
    at GuessDefaultSettingsTask.execute(GuessDefaultSettingsTask.java:11)
    at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:299)
    at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:104)
    at java.base/java.lang.reflect.Method.invoke(Method.java:577)
    at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:99)
    at org.apache.tools.ant.Task.perform(Task.java:350)
    at org.apache.tools.ant.Target.execute(Target.java:449)
    at org.apache.tools.ant.Target.performTasks(Target.java:470)
    at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1401)
    at org.apache.tools.ant.helper.SingleCheckExecutor.executeTargets(SingleCheckExecutor.java:36)
    at org.apache.tools.ant.Project.executeTargets(Project.java:1264)
    at org.apache.tools.ant.taskdefs.Ant.execute(Ant.java:437)
    at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:299)
    at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:104)
    at java.base/java.lang.reflect.Method.invoke(Method.java:577)
    at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:99)
    at org.apache.tools.ant.Task.perform(Task.java:350)
    at org.apache.tools.ant.Target.execute(Target.java:449)
    at org.apache.tools.ant.Target.performTasks(Target.java:470)
    at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1401)
    at org.apache.tools.ant.Project.executeTarget(Project.java:1374)
    at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
    at org.apache.tools.ant.Project.executeTargets(Project.java:1264)
    at org.apache.tools.ant.Main.runBuild(Main.java:818)
    at org.apache.tools.ant.Main.startAnt(Main.java:223)
    at org.apache.tools.ant.launch.Launcher.run(Launcher.java:284)
    at org.apache.tools.ant.launch.Launcher.main(Launcher.java:101)

Total time: 1 second

However, in the settings file, my android build tools is setted to location:

/Users/sioyoo/Library/Android/sdk/build-tools/32.0.0

where is actually where I kept my android build tools.

Can anyone help me with this? I am using MacOS to build this tool.


Solution

  • I solved the Problem by editing the <path_to_ella>/ella/runtime/GuessDefaultSettingsTask.java file as follows:

    import org.apache.tools.ant.*;
    import org.apache.tools.ant.taskdefs.*;
    
    import java.util.*;
    import java.io.*;
    
    public class GuessDefaultSettingsTask extends Task
    {
        public void execute() throws BuildException
        {
            String sdkPath = findAndroidSDKPath();
            String btPath = getProject().getProperty("ella.android.buildtools.dir");
            if(btPath == null){
                btPath = findAndroidBuildToolsPath(sdkPath);
                System.out.println("path to build-tools directory: "+btPath);           
            }
            File dxPath = new File(btPath, "dx");
            if(!dxPath.isFile())
                throw new Error("The configuration variable android.buildtools.dir is probably not set correctly. Current value is "+btPath);
            getProject().setProperty("ella.android.buildtools.dir", btPath);
            
            String androidJarPath = getProject().getProperty("ella.android.jar");
            if(androidJarPath == null){
                androidJarPath = findAndroidJarPath(sdkPath);
                if(androidJarPath == null)
                    throw new Error("Could not automatically infer path to android.jar. Set ella.android.jar variable in the .settings file.");
                getProject().setProperty("ella.android.jar", androidJarPath);
            }
        }
        
        String findAndroidSDKPath() 
        {
            File sdk = new File("/Users/nicoostendorf1/Library/Android/sdk");
            return sdk.getPath();
            /*
            String[] sCmdExts = {""}; //TODO: support windows?
            StringTokenizer st = new StringTokenizer(System.getenv("PATH"), File.pathSeparator);
            String path, sFile;
            while (st.hasMoreTokens()) {
                path = st.nextToken();
                for (String sExt : sCmdExts) {
                    sFile = path + File.separator + "android" + sExt;
                    File file = new File(sFile);
                    if (file.isFile()) {
                        return file.getAbsoluteFile().getParentFile().getParent();
                    }
                }
            }
            throw new RuntimeException("The executable 'android' is not in the path");*/
        }
    
        String findAndroidBuildToolsPath(String sdkPath)
        {
            /*File buildToolsDir = new File(sdkPath, "build-tools");
            //find the latest version
            String latestVersion = null;
            for(String v : buildToolsDir.list()){
                if(latestVersion == null || v.compareTo(latestVersion) > 0){
                    latestVersion = v;
                }
            }
            assert latestVersion != null : "Build tools not found";
            //return buildToolsDir.getPath()+File.separator+latestVersion;*/
            File buildToolsDir = new File("/Users/nicoostendorf1/Library/Android/sdk/build-tools/25.0.0");
            return buildToolsDir.getPath();
        }
    
        String findAndroidJarPath(String sdkPath)
        {
            File jarfile = new File("/Users/nicoostendorf1/Library/Android/sdk/platforms/android-25/android.jar");
            return jarfile.getPath();
            /*File platformsDir = new File(sdkPath, "platforms");
            String latestVersion = null;
            for(File v : platformsDir.listFiles()){
                if(!v.getName().startsWith("android-"))
                    continue;
                File androidJar = new File(v, "android.jar");
                if(androidJar.isFile())
                    return androidJar.getPath();
            }
            return null;*/
        }
    }

    You have to edit the File paths like you need it!