After installing Android SDK tools revision 14(ant version 1.8.2 when doing ant -version) to install and test our apps on Android 4.0(ICS), I've noticed that our automatic build script is now failing. The build script is executing an ant command to build the apk, which after the revision update complained about the build.xml file being out of date and to execute the ant update project -p to fix this. Our project has a top level project and two library projects it references, all developed in IntelliJ. I ran the update project command in each project folder after deleting out the old build.xml file. Now I'm getting the following message:
<SDK_DIR>/tools/ant/build.xml:466: The following error occurred while executing this line:
<SDK_DIR>/tools/ant/build.xml:539: The following error occurred while executing this line:
<SDK_DIR>/tools/ant/build.xml:568: null returned: 1
I've included the code for the main project and library projects build.xml file below(same for each):
<?xml version="1.0" encoding="UTF-8"?>
<project name="LaunchActivity" default="help">
<loadproperties srcFile="local.properties" />
<property file="ant.properties" />
<loadproperties srcFile="project.properties" />
<fail
message="sdk.dir is missing. Make sure to generate local.properties using 'android update project'"
unless="sdk.dir"
/>
<import file="${sdk.dir}/tools/ant/build.xml" />
</project>
With the new project.properties files(below):
AppMain(non-library project):
android.library.reference.1=../Common
android.library.reference.2=../facebook
# Project target.
target=Google Inc.:Google APIs:8
Common(library project):
android.library=true
# Project target.
target=Google Inc.:Google APIs:8
facebook(library project):
android.library=true
# Project target.
target=Google Inc.:Google APIs:8
Looking for a way to find out what's at the line number in the error message and/or the issue in getting this to run. I also have a build.properties file that I had included in the AppMain build.xml file to specify key.store key.alias values for creating a signed apk, which I'm assuming I can add back in to the build.xml after this issue is resolved.
The error I posted was pretty vague. So digging in a bit more, I discovered there was a way to specify an Ant logFile. I did this and found out that it was blowing up on compile. Turns out the new compiler didnt like that a few resource names in the generate R classes were the same. I renamed the ones that conflicted and after wading through a couple more compilation issues(case statements with R.id. was a no-no in this compiler version apparently) I was able to get this to work. The Ant LogFile was definitely the way to go to debug this issue. The following is what I used to generate a logFile while issuing the ant release command:
ant -logfile //antLogFile.txt release -f ./AppMain/build.xml
In my case this error occurred simply because one of my resources had a capital letter in the filename. I renamed the resource and references to it, and the error went away.
Related
Upgraded to Android Studio 0.2.0 and got the following error. The error got resolved after applying suggested solution but now the following error appeared.
Gradle:
FAILURE: Could not determine which tasks to execute.
* What went wrong:
Task 'assemble' not found in root project 'MerlinCheckProject'.
* Try:
Run gradle tasks to get a list of available tasks.
I have no clue what the error is how to solve it. Appreciate help.
Remove <component name="FacetManager"> ... </component> from your iml file.
From http://tools.android.com/knownissues:
If you get the following error message:
Gradle:
FAILURE: Could not determine which tasks to execute.
What went wrong:
Task 'assemble' not found in root project 'MyProject'.
Try:
Run gradle tasks to get a list of available tasks.
The real problem is that previous version of Android Studio misconfigured the IDEA file (e.g. MyProject.iml) -- it added an extra <component name="FacetManager"> XML element that shouldn't be present. In the case above, the solution is to edit MyProject.iml and to remove the <component name="FacetManager"> part as shown here:
<?xml version="1.0" encoding="UTF-8"?>
<module external.system.id="GRADLE" type="JAVA_MODULE" version="4">
<component name="FacetManager">
...remove this element and everything inside such as <facet> elements...
</component>
<component name="NewModuleRootManager" inherit-compiler-output="true">
...keep this part...
</component>
</module>
Alternatively you could remove the project's .idea folder and iml files and re-import your sources into a new Android Studio project.
In the next release we'll fix this -- there will be a "fix this" button to do that fix automatically for you.
In my case, in a cordova project, I had an old gradle version 1.4 and that was the problem.
So try to remove gradle
sudo apt-get remove gradle
then, download new binary relase of gradle from here . I got v3.5.1.
Finally, Create a directory for the Gradle installation.
sudo mkdir /opt/gradle
Extract the downloaded archive to the newly created directory.
sudo unzip -d /opt/gradle gradle-3.5.1-bin.zip
Configure the PATH environment variable so that the gradle executable can be directly executed anywhere on the system.
export PATH=$PATH:/opt/gradle/gradle-3.5.1/bin
You can run the following command to check if the Gradle install was successful.
gradle -v
Deleting the facet-manager component from IML file did not solve the problem for me. I got the same error and closing and reopening the project caused the facet-manager component to be recreated in the iml file.
I had to delete the .idea directory and the .iml file and then import the top level gradle.build file to solve the problem. I was able to import the project in place using the import option on the initial Android Studio menu (with no project open).
The solution works fine. If you're having issues with it, ensure you close Android Studio completely, then edit the file, then reopen it.
I am a Windows user. The solution that worked for me was to remove the previous version of Android Studio:
http://developer.android.com/sdk/installing/studio.html#Updating
Inspired by the answer from #Dhafer.Dhib to check the installed gradle version, I want to add: The recommended way to install gradle under linux is using sdk, see https://gradle.org, I did the following steps:
sudo apt install zip ## zip required by SDKman, see http://sdkman.io/
## do the following steps as the user who wants to use the tools NOT root!
curl -s "https://get.sdkman.io" | bash ## SDKman recommended option to install *up-to-date* gradle, see https://gradle.org/install/
source "/root/.sdkman/bin/sdkman-init.sh" ## set env to use sdk without opening a new shell
sdk install gradle 4.6
gradle -v
I want to set up a ant build for my project. I found a tutorial saying that I need to write the following command in order to prepare for ant build:
android update project -p
then I get the result
Updated local.properties
Updated file ./proguard-project.txt
It seems that there are sub-projects. If you want to update them
please use the --subprojects parameter.
so If I try
android update project -p . --subprojects
then I get:
Updated local.properties
Updated file ./proguard-project.txt
Error: The project either has no target set or the target is invalid.
Please provide a --target to the 'android update' command.
and if I try
ant release
I get
sdk.dir is missing. Make sure to generate local.properties using 'android update project' or to inject it through an env var
Can some one please help me in setting up the project with ant.
Thanks
I also had the same problem.
My problem problem got solved by the following command.
android update project --path . --subprojects --target android-19
ANT will automatically set your sdk.dir into correct one.
Don't put anything inside your local.properties.
# This file is automatically generated by Android Tools.
# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
#
# This file must *NOT* be checked into Version Control Systems,
# as it contains information specific to your local configuration.
# location of the SDK. This is only used by Ant
# For customization when using a Version Control System, please read the
# header note.
Be sure to have a target set in your projects (main project and libraries as well).
on Eclipse:
Right click on the project -> Properties -> Android and select your target SDK. This means the Android SDK version you are targeting. If you take a look in the manifest.xml, you should see that almost at the beginning:
<uses-sdk
android:minSdkVersion="9"
android:targetSdkVersion="17" />
This is the target version for your project, and usually is recommended to be as highest (newest) as possible.
After that, be sure that the file project.properties has a line similar to this one:
target=Google Inc.:Google APIs:17
This file will be read by ANT to know the target of your project. You can add that line manually. Actually, I'm pretty sure that will be included automatically if you set the target for the projects in Eclipse (as I said above) before running android update project -p . --subprojects
About this error:
sdk.dir is missing. Make sure to generate local.properties using 'android update project' or to inject it through an env var
It means you didn't define the sdk.dir property, which should point to the android sdk root directory in your file system. After running android update project -p . --subprojects it should be generated automatically for all your projects. It's possible that it wasn't due to the previous error. So check all your projects for the file called local.properties and be sure that contains a line similar to this:
sdk.dir=/home/path/to/android/sdk/android-sdk-linux
I'm having trouble building my project with Jenkins and referencing the Sherlock project library.
I can build the project with ant on my local system. The problem seems to be referencing the Sherlock library on the build server.
I pass an environment variable to ant with the relative path to the Sherlock library project:
android.library.reference.1=../../buildlibraries/androidlibraries/sherlock/library
I'm getting this error.
**BUILD FAILED**
/SDK/android-sdk-macosx/tools/ant/build.xml:595:
The following error occurred while executing this line:
/SDK/android-sdk-macosx/tools/ant/build.xml:571:
../../buildlibraries/androidlibraries/sherlock/library resolve to a path with
no project.properties file for project /Users/Jenkins/buildlibraries/androidlibraries/sherlock/library
I checked and a project.properties file does exist at that location.
It has these properties:
android.library=true
# Project target.
target=android-14
I had the same thing happen to me just now. I use both a Windows and Mac to develop with. I watne d to test my project on both platforms. It built just fine on my Windows machine, but broke on my Mac. When I looked at my project.properties in my Android application (not library projects) on the Mac, I saw that my library projects were referenced this way:
android.library.reference.1=LibraryProjects\\my_lib_project
I changed it to the line below, and it worked just fine!
android.library.reference.1=LibraryProjects/my_lib_project
I solved the issue by editing and checking in the project.properties file with the same property: android.library.reference.1=../../buildlibraries/androidlibraries/sherlock/library
I'm not sure why it works. Why would ant care if the property is passed in by Jenkins vs. declared in the project's property file?
Now I have two paths in my project.properties file: one for a local build and one for the build on Jenkins.
I had similar issue with error ../google-play-services_lib resolve to a path with no project.properties file for project. It has to work in Jenkins CI (Cloudbees), so no manual project.properties editing.
My solution was to replace android update lib-project --path ... with ugly but working echo "android.library.reference.1=../../../..$ANDROID_HOME/extras/google/google_play_services/libproject/google-play-services_lib" >> project.properties in Jenkins shell command.
I had this problem because I hadn't downloaded the google play services package using the android tool. When I checked my android sdk directory ($ANDROID_HOME) there was no "$ANDROID_HOME/extras/google" folder.
I fixed this by running android and downloading "Google Play services" found in the extras section.
I'm adding an android library project to my android app (in this case, Beintoo). It's not mine; It's an external library. However, it doesn't come with a build.xml. Building in Eclipse works fine, but when I attempt to build my app with ant, I get this:
BUILD FAILED
C:\Sandbox\MyProject\build.xml:110: The following error occurred while executing this line:
C:\Sandbox\MyProject\build.xml:41: The following error occurred while executing this line:
C:\Program Files (x86)\Android\android-sdk\tools\ant\build.xml:515: Invalid file: C:\Git\Beintoo-Android\beintoo-android-sdk\BeintooSDK\build.xml
It's perfectly true. The file is invalid, because it doesn't exist. I wouldn't know what to do to add it safely, nor if that's even a good idea.
I have learnt that I can't simply build the library project into a jar. How can I get my project to build in Ant with this library project?
Ok, so, Error 454's answer was close, but not quite right. Since r14 of Android Tools, every library project must have it's own build.xml if it is to be built by Ant, as noted here:
https://groups.google.com/forum/?fromgroups#!topic/adt-dev/Z2e3dY-3Ma0
Running android update lib-project (which, as Error 454 notes, is in the android-sdk/tools folder which should be in PATH) on the library project will add a generic build.xml, and allow the main project to build.
For library projects, you need to browse to the library project root and run:
android update lib-project -p .
The android executable is in the android sdk/tools folder which should be added to your path variable in your OS. Once you run this, the necessary build files will be generated and your ant build should succeed.
Similarly, if your root project doesn't have the necessary build files, you will need to browse to the main project root and run:
android update project -p .
Additionally to the two previous correct answers I had to add --target android-16 because I was getting an "Error: The project either has no target set or the target is invalid."
So in my case
android update lib-project -p . --target android-16
Did it. (replace the 16 as you need)
I am following the instructions to build Scala app for Android at:
scala-to-android
Basically, I installed Scala and changed the ant build.properties to point to Scala and changed build.xml to include build-scala.xml.
ant scala-compile
is successful, However,
ant debug
generates the following build errors:
scala-compile:
-shrink-if-test:
[echo] Checking if Scala libraries are installed on emulator or device...
[adb] BOOTCLASSPATH=/system/framework/core.jar:/system/framework/ext.jar:/system/framework/framework.jar:/system/framework/android.policy.jar:/system/framework/services.jar
-shrink-config:
[taskdef] Could not load definitions from resource scala/tools/ant/task.properties. It could not be found.
BUILD FAILED
/home/salil/Programs/android-projects/FirstScala/build-scala.xml:82: Problem: failed to create task or type invoked
Cause: The name is undefined.
Action: Check the spelling.
Action: Check that any custom tasks/types have been declared.
Action: Check that any <presetdef>/<macrodef> declarations have taken place.
I am a beginner in ant, Android and Scala. Any help would be appreciated. Thanks so much in advance!
I faced the same issue with android dev on Scala. Actually the build script looks for a file named task.properties which is located in scala/tools/ant/task.properties. This is packed inside the jar ant-invoked.jar. I hope you would have downloaded the android-sdk project zip archive from that site. Just copy the folder "configs" from the android-sdk root into your project root folder, this will work.
This is were it searches for the file in scala-build.xml
<!-- Project settings -->
property name="configs.dir" value="${basedir}/configs" />
<property name="ant-invoked.jar" value="${configs.dir}/ant/ant-invoked.jar" />
and the target shrink-config
<target name="-shrink-config"
description="Generate ProGuard configuration file">
<taskdef resource="scala/tools/ant/task.properties"
classpath="${ant-invoked.jar}" />
Currently, the most stable way to use Scala with android is to use the Simple Build Tool (SBT) and the Android Plugin
It basically "just works", handling all the steps for you and shrinking with Proguard.
Hi I have a blog here that documents steps to make scala work on android. It makes use of android ant process and sticks close to the android way. You can see the tutorial here
http://saadstechblog.blogspot.com/2011/09/scandroid-scala-android-tutorial.html. There is also a github project with all the configuration.