蚂蚁构建错误 "java.lang.RuntimeException: The executable 'android' is not in the path"
ant build error "java.lang.RuntimeException: The executable 'android' is not in the path"
我正在尝试从 https://github.com/saswatanand/ella
构建一个名为 Ella 的 Android 应用检测工具
当我尝试使用 ant 构建它时,它显示了这个错误:
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
但是,在设置文件中,我的 android 构建工具设置为位置:
/Users/sioyoo/Library/Android/sdk/build-tools/32.0.0
实际上我存放 android 构建工具的地方。
谁能帮我解决这个问题?我正在使用 MacOS 构建此工具。
我通过编辑解决了问题
/ella/runtime/GuessDefaultSettingsTask.java文件如下:
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;*/
}
}
您必须根据需要编辑文件路径!
我正在尝试从 https://github.com/saswatanand/ella
构建一个名为 Ella 的 Android 应用检测工具当我尝试使用 ant 构建它时,它显示了这个错误:
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
但是,在设置文件中,我的 android 构建工具设置为位置:
/Users/sioyoo/Library/Android/sdk/build-tools/32.0.0
实际上我存放 android 构建工具的地方。
谁能帮我解决这个问题?我正在使用 MacOS 构建此工具。
我通过编辑解决了问题
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;*/
}
}
您必须根据需要编辑文件路径!