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
Related
I have seen this same thing posted quite a few times, but whenever I try to import my project to my new work laptop I keep getting this error.
I have pulled the project from git (which his btw running fine on my old laptop).
Then I went to the sdk manager, downloaded all the tools, and all the SDK's available.
In the welcome screen, I went to Configure -> project Defaults -> Project structure.
Android SDK Tab says the path for projects without local.properties will be /Applications/Android Studio.app/sdk
This is correct.
Under SDKs I have all the available SDK's visible.
Project SDK is set to API 18
Yet still I get this error when trying to build my project.
Can anyone tell me where I havent looked yet?
I am running gradle 1.7 when trying to build which is downloaded from services.gradle.org
I had very similar situation (had a project on another machine and cloned it to my laptop and saw the same issue) and I looked in it.
Error message was coming from Sdk.groovy of Android gradle plugin:
https://android.googlesource.com/platform/tools/build/+/master/gradle/src/main/groovy/com/android/build/gradle/internal/Sdk.groovy
By looking at code, its findLocation needs to set androidSdkDir variable and there are only three ways to do it:
create local.properties file and have either sdk.dir or android.dir line.
have ANDROID_HOME environment variable defined.
System.getProperty("android.home") - I'm not sure how it works, but it seems like a Java thing.
While your Android Studio knows that the SDK is at that place, I doubt that Android Studio is passing that information to gradle and thus we're seeing that error.
I created local.properties file at the project root and put the following line and it compiled the code successfully.
sdk.dir = /Applications/Android Studio.app/sdk/
creating local.properties file in the root directory solved my issue
I somehow lost this file after pulling from GitHub
this is how my local.properties file looks like now:
## This file is automatically generated by Android Studio.
# 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 Gradle.
# For customization when using a Version Control System, please read the
# header note.
#Sat Feb 06 11:53:03 EST 2016
sdk.dir=/Users/****/Library/Android/sdk
I found the solution here:
http://xinyustudio.wordpress.com/2014/07/02/gradle-sdk-location-not-found-the-problem-and-solution/
Just create a file local.properties and add a line with sdk.dir=SDK_LOCATION
If none of the answers work for you which happened to me on macbook pro in one of the projects you can always try to run Android Studio with an alias command passing sdk.dir with each run:
alias studio='launchctl setenv ANDROID_HOME '\''/Users/username/Library/Android/sdk'\'' && open -a '\''Android Studio'\'''
To fix this problem, I had to define the ANDROID_HOME environment variable in the Windows OS.
To do this, I went to the System control panel.
I selected "Advanced system settings" in the left column.
On the "Advanced" tab, I selected "Environment Variables" at the bottom.
Here, I did not have an ANDROID_HOME variable defined. For this case, I selected "New..." and:
1) for "Variable name" I typed ANDROID_HOME,
2) for "Variable value", I typed the path to my SDK folder, e.g. "C:\...\AppData\Local\Android\sdk".
I then closed Android Studio and reopened, and everything worked.
Thanks to Dibish (https://stackoverflow.com/users/2244411/dibish) for one of his posts that gave me this idea.
Had the same problem in IntelliJ 12, even though I have ANDROID_HOME env variable it still gives the same error. I ended up creating local.properties file under the root of my project (my project has a main project w/ a few submodules in its own directories). This solved the error.
specifying sdk.dir=<SDK_PATH> in local.properties in root folder solved my problem.
I clone libgdx demo, can't import project. it also reminds like this.
Env:
Eclipse(Android-ADT)
window 7
so I create local.properties file at the project root, like following
sdk.dir = D:/adt-bundle-windows-x86/sdk
I hope this can help others!
Copy and paste the local.properties file from a project you created on your new computer to the folder containing the project from your old computer also works too if you don't want to (or know how to) create a new local.properties file.
I noticed that I get this error when I'm working on a new computer if I try to build from the command line first. However, if I build from Android Studio, it retrieves the SDK and creates the directory automatically. Then when I build from the command line it works.
You have also to ensure you have the correct SDK platform version installed in your environment by using SDK Manager.
If you have cloned a project from GitHub for example, and you've tried the methods mentioned here without success including:
Editing sdk.dir in the local.properties
Trying to set ANDROID_HOME environment variable
Or adding an alias as kasiara mentioned
You should try to see if you are trying to build a directory project that is a part within a bigger project, and so it may cause problems.
So load the entire project, and then run the project directory you'd like.
In my specific case I tried to create a React Native app using the react-native init installation process, when I encountered the discussed problem.
FAILURE: Build failed with an exception.
* What went wrong:
A problem occurred configuring project ':app'.
> SDK location not found. Define location with an ANDROID_SDK_ROOT environment variable or by setting the sdk.dir path in your project's local properties file at 'C:\Users\***\android\local.properties'.
I add this, because when developing an android app using react native, the 'root directory' to which so many answers refer, is actually the root of the android folder (and not the project's root folder, where App.js resides). This is also made clear by the directory marked in the error message.
To solve it, just add a local.properties file to the android folder, and type:
sdk.dir=C:/Users/{user name}/AppData/Local/Android/Sdk
Be sure to add the local disk's reference ('C:/'), because it did not work otherwise in my case.
I'm trying to build an app (let's call it android-app) with a dependency on an SDK (let's call it sdk) via Ant. Eclipse is not installed on this computer (for reasoning, it's a CI box with Jenkins).
Both projects are in two completely separate directories side by side. android-app is in the directory ~/.jenkins/jobs/android-app/workspace and sdk is in the directory ~/.jenkins/jobs/sdk/workspace.
Let's assume both projects are "vanilla" and have not been built with Ant before. I cd to the ../android-app/workspace directory and run android update project -p . --library ~/.jenkins/jobs/sdk/workspace which passes. I then cd to the ../sdk/workspace directory and run android update project -p . which also passes.
At this point I cd back to the ../android-app/workspace directory and run ant clean build. It fails with the error:
BUILD FAILED
/path/to/ant/build.xml:440:
/path/to/sdk/workspace resolve to a path with no project.properties file for
project /path/to/android-app/workspace
... where /path/to is the full path to the directories. I simplified it here.
If I cd to the sdk workspace and open project.properties, I receive the following:
# ProGuard
proguard.config=proguard.cfg
# Project target.
target=android-10
android.library=true
It does exist. So do all of these files:
So, why is this failing? What am I doing wrong? I tried to provide as many details as possible. Please let me know if I can provide anything additional.
Well, I encounter this problem too.
I use strace to find out what the hell is going on and found that the path you specified in project.properties will be appended with your current folder path as its prefix.
For example,
/home/myfolder/project > ant debug
And the library you specified in project.properties is /path/to/library
Then, the path will become
/home/myfolder/project/path/to/library
Just to fill in the answer gap here, my Java version was completely off. I'm super embarrassed.
I get this error when I do
$ ant release
sdk.dir is missing. Make sure to generate local.properties using 'android update project' or to inject it through an env var
typing in android update project I get another error saying I must specify the path .... to the project.
Then I try cd into the directory of my project and do
android update -p .
android update -path .
etc and it says -p and -path are not globally recognized.
Could someone just give me the exact syntax?
cd to project directory and execute the following: The word project is part of the command, and is not to be replaced with an actual project name. The documentation does not make this clear and should be improved.
android update project -p .
You can use the command line argument for setting the sdk.dir, e.g:
ant -f xyz/build.xml clean release -Dsdk.dir=/Applications/adt-bundle-mac/sdk/
You can use sdk.dir in projet.properties file to define the sdk home or use an environment variable (more flexible for team work).
export ANDROID_HOME=<the path to your sdks>
You can inject the ANDROID_HOME environment variable into the sdk.dir property using the following ant command.
$ ant debug -Dsdk.dir=$ANDROID_HOME
ANDROID_HOME must be an absolute path such as /Users/jameswald/Development/android-sdk-macosx.
I had the same problem. After flailing around with the command line commands for a few minutes I ended up just editing the local.properties files directly.
You should have a file called local.properties within your
<app-directory>\platforms\android
folder. If you don't have one then you can create it.
Within the file there should be a reference that specifies where ant can find your android sdk. It should look like this:
sdk.dir=C:\\<path-to-sdk>\\sdk
Just update your details to point it to your correct android sdk folder.
The double \ are present in my file. Not sure why but it seems to work. :)
Note: this file also needs to be copied into your CordovaLib folder, which is one folder deeper: <app-directory>\platforms\android\CordovaLib
That should create/fix the local.properties from ant:
android update project --name --target
--path
name parameter is optional
target is the api version
More info here
https://developer.android.com/tools/projects/projects-cmdline.html#UpdatingAProject
android update project -p . might fix your issue. Sometimes once you execute android update project -p . You might end up with a O/P Like this.
Updated local.properties
----------
build.xml: Failed to find version-tag string. File must be updated.
In order to not erase potential customizations, the file will not be automatically regenerated.
If no changes have been made to the file, delete it manually and run the command again.
If you have made customizations to the build process, the file must be manually updated.
It is recommended to:
* Copy current file to a safe location.
* Delete original file.
* Run command again to generate a new file.
* Port customizations to the new file, by looking at the new rules file
located at <SDK>/tools/ant/build.xml
* Update file to contain
version-tag: custom
to prevent file from being rewritten automatically by the SDK tools.
----------
Updated file ./proguard-project.txt
It seems that there are sub-projects. If you want to update them
please use the --subprojects parameter.
If so try this command android update project -p . -s
the ANDROID_HOME must be set in the right context - just that you have it e.g. on your bashrc does not mean the var is set when you launch by clicking the icon ( bashrc doesn not get executed then - but when checking if the env var is set on the console it is )
you can also put it in the studio.sh:
#!/bin/sh
#
# ---------------------------------------------------------------------
# Android Studio startup script.
# ---------------------------------------------------------------------
#
export ANDROID_HOME=/home/ligi/bin/android-sdk/
message()
{
I had the same problem and it turned out that one of the ant scripts for some reason is referencing hard coded path to C:\ant and as my ant was in C:\apache-ant-{version} it could not find it. After renaming the ant directory everything worked fine.
For reference the file where I observed this issue was
\apache-ant-{version}\bin\ant.bat :line 106
Edit: I am using windows 8
Yeah, none of these solutions worked for me. This did from here:
Setting ANDROID_HOME enviromental variable on Mac OS X
Open the terminal window and enter the following (I hope this is the complete path to sdk):
export ANDROID_HOME=/Applications/ADT/sdk
Once you have this set, you need to add this to the PATH environment variable
export PATH=$PATH:$ANDROID_HOME/bin
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 running the standard ant script build.xml which gets created when you run the android create project command. In order to verify my local.properties is set correctly, I added a task at the beginning of the build.xml script to run the command:
android update project -p .
I now get the following message each time I run the ant script, which clobbers my build.xml file and creates a proguard.cfg file!
File build.xml is too old and needs to be updated
So, I moved the ant script to a different file that won't get clobbered.
Is there a way to run the command android update project -p . that doesn't clobber build.xml and create proguard.cfg?
I think this is a bug. I have registered a new bug with Google here:
http://code.google.com/p/android/issues/detail?id=17825
If anyone else thinks it's a bug, then please star it and perhaps contribute your thoughts.
Workaround for this. Add the following code in build.xml.
<!-- The following will prevent for 'android' tool to overwrite this file.
(until sdk r12)
classname="com.android.ant.SetupTask"
(since sdk r13 FIXME)
version-tag:custom
-->
With the piece of comment, 'android update project' will not complaint or overwrite the build.xml.
As of now, there might be chance for changes in r13.
sdk r13 not yet released
it's based on aosp/master branch
updateProject() in package com.android.sdklib.internal.project.ProjectCreator determine to update the build.xml or not.
(The code from sdkmanager/libs/sdklib/src/com/android/sdklib/internal/project/ProjectCreator.java)
The build.xml generated by android has the following comment:
****** IMPORTANT ******
***********************
In all cases you must update the value of version-tag below to read 'custom' instead of an integer,
in order to avoid having your file be overridden by tools such as "android update project"
so, it looks like Atham is right.