I am trying to generate apk on command line using ant. I am able to use ant clean but for ant debug and ant release command I am getting following error.
BUILD FAILED
C:\Android\sdk\tools\ant\build.xml:649: The following error occurred while executing this line:
C:\Android\sdk\tools\ant\build.xml:694: Execute failed: java.io.IOException: Cannot run program "C:\Workspace\SampleApp\${aapt}": CreateProcess error=2, Th
e system cannot find the file specified
at java.lang.ProcessBuilder.start(ProcessBuilder.java:1047)
at java.lang.Runtime.exec(Runtime.java:617)
at org.apache.tools.ant.taskdefs.launcher.Java13CommandLauncher.exec(Jav
a13CommandLauncher.java:58)...
On line build.xml:694 proguardFile="${out.absolute.dir}/proguard.txt"> line is present. I am using Eclipse Juno and build target is 22 (Lollipop).
Any help is appreciated.
I had the same error after updating the android SDK to the latest build tools.
The tools\ant\build.xml script does not contain any references for the tools.
This can be solved, by adding the tools to the build.xml and point to the correct path. For me this was build-tools\22.0.1
Please compare and update the tool section in build.xml
<!-- tools location -->
<property name="android.tools.dir" location="${sdk.dir}/tools" />
<property name="android.platform.tools.dir" location="${sdk.dir}/platform-tools" />
<property name="android.buildtools.dir" location="${sdk.dir}/build-tools/22.0.1" />
<condition property="exe" value=".exe" else=""><os family="windows" /></condition>
<condition property="bat" value=".bat" else=""><os family="windows" /></condition>
<property name="adb" location="${android.platform.tools.dir}/adb${exe}" />
<property name="lint" location="${android.tools.dir}/lint${bat}" />
<property name="zipalign" location="${android.buildtools.dir}/zipalign${exe}" />
<property name="aidl" location="${android.platform.tools.dir}/aidl${exe}" />
<property name="aapt" location="${android.buildtools.dir}/aapt${exe}" />
<property name="dx" location="${android.buildtools.dir}/dx${bat}" />
<property name="renderscript" location="${android.buildtools.dir}/llvm-rs-cc${exe}"/>
<property name="lint" location="${android.tools.dir}/lint${bat}" />
Thank you Alex for the tip!
This bit Cannot run program "C:\Workspace\SampleApp\${aapt}"suggests that the variable ${aapt} has not been translated by the compiler.
Check that ${aapt} has been defined earlier in your build script. Try printing out value of ${aapt} (e.g. <echo>aapt variable: ${aapt}</echo>) immediately before the line that triggers the error, to check that the build has correctly compiled the variable.
Just update android sdk tool to 24.3.3
make sure the proguard.config point to an existing proguard file in your project.properties
proguard.config=proguard-project.txt
Related
im trying to run my junits, but intellij give me a error:
I have seen the error on many sites, but the configuration page is different than the current one from intellij.
Now, intellij-idea have this configuration page:
What would I have to modify to be able to fix it?
Here is my intellij info:
IntelliJ IDEA 2020.3.2 (Ultimate Edition) Build #IU-203.7148.57, built on January 26, 2021 Runtime version: 11.0.9.1+11-b1145.77 amd64 VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o. Windows 10 10.0 GC: ParNew, ConcurrentMarkSweep Memory: 1955M Cores: 8 Non-Bundled Plugins: com.dubreuia, org.sonarlint.idea, org.jetbrains.kotlin
Greetings and thank you very much: D
From this link: https://devis.cool/quick-fix/quickfix-intellij-idea-command-line-is-too-long-shorten-command-line-for/
Open file from project root folder .idea/workspace.xml, go to section and add the following:
<property name="dynamic.classpath" value="true" />
It should look something like this:
<component name="PropertiesComponent">
<property name="dynamic.classpath" value="true" />
<property name="WebServerToolWindowFactoryState" value="false" />
<property name="aspect.path.notification.shown" value="true" />
<property name="last_opened_file_path" value="$PROJECT_DIR$/pom.xml" />
<property name="nodejs_interpreter_path.stuck_in_default_project" value="undefined stuck path" />
<property name="nodejs_npm_path_reset_for_default_project" value="true" />
</component>
It worked for me.
You can shorten the command line, by checking "Shorten Command Line" in the "Add Run Options" menu that is found under "Modify Options" in the "Build and Run" tab for the test configure - as shown below.
You can shorten the command line, by checking "Shorten Command Line" in the "Add Run Options" menu that is found under "Modify Options" in the "Build and Run" tab for the test configure - as shown below.
This option worked for me. Make sure you are checking the below shorten command line argument properly
I am working on an ant build script. How do i set the two property value with the same name:
<property name="java.src.dir" location="src" />
<property name="java.src.dir" location="src/java" />
In my application some of the directories are src/java and some are src. I need to make it flexible enough to work on both.
My NetBeans project creates my.jar file in /dist/ directory. Trying to edit build.xml to copy this file to another location using ssh. But how to know what is target file name property?
<property name="username" value="aaa"/>
<property name="password" value="bbb"/>
<property name="ip" value="10.1.100.55"/>
<property name="dir" value="/opt/aaa/"/>
<scp file="${dist.jar.dir}${??target??}" todir="${username}:${password}#${ip}:${dir}" trust="true" />
Your Netbeans project has a nbproject/project.properties file, which gets included in build.xml (indirectly) and contains lots of useful variables - including the one that contains a file path to the built jar file. It should be called dist.jar.
<scp file="${dist.jar}" todir="${username}:${password}#${ip}:${dir}" trust="true" />
Check the actual properties file for more variable names, such as dist.dir, src.dir, etc.
I am attempting to get my JUnit tests for an Android application running using Ant.
While using Eclipse, it is no problem, all is compiled and can be run with no problem.
At the moment I am receiving a ClassNotFoundException to org.junit.Test.
I am running the following commands
ant clean debug - success
ant uninstall - success
ant installt - success
ant test - failure
error log:
test:
[echo] Running tests ...
[exec] INSTRUMENTATION_RESULT: shortMsg=java.lang.ClassNotFoundException
[exec] INSTRUMENTATION_RESULT: longMsg=java.lang.ClassNotFoundException: org.junit.Test
[exec] INSTRUMENTATION_CODE: 0
I suppose, it misses junit.jar file. I added it into my ANT_HOME/lib directory, but it didn't have any effect. ant-junit.jar library was already in "ANT_HOME/lib", I didn't need to copy it over.
I also tried to add it in the classpath of my test project and marked it to be exported. Also in that case the result remains unchanged.
I also let eclipse to generate a build.xml to be and merged it with the file generated by android update project. It didn't make any difference, I receive the same error.
I am sure that I am missing something very easy here. If further configuration details are needed, I'll be glad to provide them. I appreciate your help.
build.xml:
<?xml version="1.0" encoding="UTF-8"?>
<project name="FSTest" default="help">
<property file="local.properties" />
<property file="ant.properties" />
<property environment="env" />
<condition property="sdk.dir" value="${env.ANDROID_HOME}">
<isset property="env.ANDROID_HOME" />
</condition>
<loadproperties srcFile="project.properties" />
<fail
message="sdk.dir is missing. Make sure to generate local.properties using 'android update project' or to inject it through the ANDROID_HOME environment variable."
unless="sdk.dir"
/>
<import file="custom_rules.xml" optional="true" />
<import file="${sdk.dir}/tools/ant/build.xml" />
</project>
ant.properties:
tested.project.dir=../FS
external.libs.dir=libs
project.properties:
target=android-11
The problem was in my build.xml file. I modified it according to the example given here: http://www.vogella.com/articles/ApacheAnt/article.html and thereafter it worked.
These lines were the ones that maked the difference:
<path id="junit.class.path">
<pathelement location="libs/junit.jar" />
<pathelement location="${build.dir}" />
</path>
The JUnit task page lists several ways in which you can make the JUnit jar available to Ant:
http://ant.apache.org/manual/Tasks/junit.html
In particular, option 1 would require adding both "junit.jar" and "ant-junit.jar" to "ANT_HOME/lib". Any of the 5 options listed there should work just fine though.
I am building an Android app in Eclipse and have two similar apps based on the same code base, a 'London' one and a 'UK' one. To build each app, I just re-name the main package and change a static int in the Application class. The app uses the value of this int to display the right UI, restrict user behaviour, etc.
I have two icon files, one for each app:
res/drawable-hdpi/icon_london.png
res/drawable-hdpi/icon_uk.png
Is there any way to conditionally use the correct icon file for the Application and Activities depending upon some sort of project configuration setting? Otherwise, the project maintenance is increased as I would have to change my manifest each time the code base changes, e.g.
<application
android:icon="#drawable/icon_london"
...
>
<activity
android:name="com.company.MainActivity"
android:logo="#drawable/icon_london"
>
</activity>
...and so on, for all the activities.
I had a similar issue, and ended up in building my custon Ant script to build the apps. You can run macros or Regular Expressions to assign one resource or another.
EDIT:
First, add build.xml to the project:
Open up a command prompt and navigate to the directory of your project:
android update project --path
Then, you can override the existing build.xml, for something like the following.
NOTE: This Ant script is just an example, I have not tested it:
<?xml version="1.0" encoding="UTF-8"?>
<project name="Example" default="help">
<property file="local.properties" />
<property file="ant.properties" />
<loadproperties srcFile="project.properties" />
<!-- quick check on sdk.dir -->
<fail
message="sdk.dir is missing. Make sure to generate local.properties using 'android update project' or to inject it through an env var"
unless="sdk.dir"/>
<!-- IMPORT ANT?S BUILD.XML -->
<import file="${sdk.dir}/tools/ant/build.xml" />
<property name="app.icon" value="${icon}" />
<property name="icon.file" location="res/drawable/icon.png" />
<target name="test-release">
<antcall target="test-pre-release" />
<antcall target="release" />
</target>
<target name="test-pre-release">
<copy file="${app.icon}" tofile="${icon.file}" overwrite="true"/>
</target>
</project>
Then, to build this project with a custom icon, open up the command prompt and go to the project directory:
CALL ant -f build.xml test-release -Dicon=path/to/your/icon.png
As said, this is a very basic example. To build a good script, you'll have to learn a bit of Ant syntax, but it's not difficult.