How to run "android.bat sdk" in Windows 7 - android

I have downloaded and installed Android SDK and tried to start android.bat sdk but got following exception:
C:\products\Android\tools>android.bat sdk
Exception in thread "main" java.lang.UnsatisfiedLinkError: no swt-win32-3550 or swt-win32 in swt.library.path,
java.library.path or the jar file
at org.eclipse.swt.internal.Library.loadLibrary(Unknown Source)
at org.eclipse.swt.internal.Library.loadLibrary(Unknown Source)
at org.eclipse.swt.internal.C.<clinit>(Unknown Source)
at org.eclipse.swt.widgets.Display.<clinit>(Unknown Source)
at com.android.sdkmanager.Main.showSdkManagerWindow(Main.java:328)
at com.android.sdkmanager.Main.doAction(Main.java:302)
at com.android.sdkmanager.Main.run(Main.java:118)
at com.android.sdkmanager.Main.main(Main.java:101)
I have searched for solution a long time but I cannot get it to work. Is there anything I have to set up first?

Just in case this is still bothering anyone: I had this same problem. What I ended up doing was:
Searching for the swt.jar file (in your Android SDK directory, look at tools\lib\x86 or tools\lib\x86_64).
Unpack it using jar:
mkdir tmp
cd tmp
jar xf <path>\tools\lib\x86\swt.jar
Copy the dlls to the tools folder.
copy tmp\*.dll <path>\tools
After that I was able to run the SDK manager.

This works for me:
Add the following in your android.bat file:
-Dswt.library.path = {swt.jar folder path}
before this phrase:
com.android.manager.Main
Run android.bat

I think the jar file is not placed in correct place.
SWT consists of two "parts" - the platform independent java-only part
and a platform dependent fragment. Did you add the platform dependent
fragment too?So you need
org.eclipse.swt_VERSION.jar
org.eclipse.swt_WINDOWSYSTEM_PLATFORM_VERSION.jar
Refer this link for Setting the class path.
SWT Programming with Eclipse.

I had the same message displayed in the eclipse console when I was trying to load the sdk manager from within eclipse. All you need to do to fix it is run eclipse as administrator and it should work fine

Change the path to swt.jar.
edit "[your sdk_path]\tools\android.bat" file.
find words "%Swt_path%\swt.jar"
Find your Eclipse plugin folder path.
be replace path by [your eclipse\plugins\swt.jar]
example
before classpath "% jar_path%;% swt_path%\swt.jar"
after classpath "% jar_path%; C:\eclipse\plugins\ org.eclipse.swt.win32.win32.x86_3.102.1.v20130827-2048.jar"
I hope this will help resolve the way.

This questions its rather old, but I ran with the same issue as today, in 2015.
Also I expected the answers may not work, but oriented me to get this running without the need of running as Administrator, specially "Mehdi golnari" answer.
Based on Mehdi answer, we need add the same parameter that he added, but updated to work on the new SDK Tools (or android SDK). Mine is revision 24.3.3, SDK , so the com.android.manager.Main will not longer work for me, but insted we need it to be com.android.sdkmanager.Main.
Also we can use the variable that was set in the same bat before: %swt_path%.
So, add the following, almost at the end of the android.bat file:
"-Dswt.library.path=%swt_path%"
The resulting call code, should be a single line like this:
call "%java_exe% %REMOTE_DEBUG%" "-Dcom.android.sdkmanager.toolsdir=%tools_dir%" "-Dcom.android.sdkmanager.workdir=%work_dir%" -classpath "%jar_path%;%swt_path%\swt.jar" "-Dswt.library.path=%swt_path%" com.android.sdkmanager.Main %*
This should help to run the android.bat, SDK Manager.exe, and AVD Manager.exe without run as Administrator needs.

Related

SDK Location not found Android Studio + Gradle

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.

How to configure javah tool in Eclipse [duplicate]

This question already has answers here:
Using javah on linux
(2 answers)
Closed 8 years ago.
I found already about 5 answers, tried all of them and didn't get it working.
Env: Ubuntu 12.04/ Indigo
Run->External Tools->External Tools Configuration...
Created new Program
Location: /usr/bin/javah /*$ which javah gives /usr/bin/javah */
Working directory: ${workspace_loc:/MyProject/bin/classes}
Attributes: -d ${workspace_loc:/MyProject/jni} com.myproject.MyActivity
Result of RUN: Could not find class file for 'com.myproject.MyActivity'
Run from terminal gives same result
maxim#ubuntu:~/workspace/MyProject/bin/classes$ javah -jni com.myproject.MyActivity
Error: cannot access android.app.Activity
class file for android.app.Activity not found
maxim#ubuntu:~/workspace/MyProject/bin/classes$
SDK/NDK installed, external paths added.
How to add missing parts? Thanks everybody.
Edited Jul 3
Moving native lib loading to a separate class solved the problem
Elaborating on this post also mentioned in android developer's answer:
As you can see by the screen shot below, set up the external tools like this:
In the Eclipse ADT, click on "Run", hover on the last option of the menu - "External Tools" and choose "External Tools Configurations"
Set the paths up to the following:
2.1. Location: wherever you installed Java
C:\Program Files\Java\jdk1.7.0_13\bin\javah.exe
2.2. Working Directory: your project's /bin/classes/ directory
${workspace_loc:/MyProject/bin/classes}
2.3. Arguments:
-jni ${java_type_name}
Click on run (note that you have to have the java class selected)
Using your file browser, check the /bin/classes/ directory - you should find the .h header file there.
Hope this helps someone.
I had a very similar problem on linux too . it turned out that i didn't do it on the right folder.
Try to read it and see if it helps: Using javah on linux.
Based on Enke's answer I added more argument for convenience.
1.You don't have to set working dir correctly by using "-classpath ".(You can ignore the working dir setting in the pic.)
2.You can get verbose info from integrated console in Eclipse.
3.You can specify output dir by using "-d " parameter.
*Don't forget to replace the project directory name in this pic.("MyProject")

Regenerating of R class in android project (eclipse)

Editing the xml files didn't help, cleaning the project didn't help and, of course, trying to run the project didn't help because the project contains errors (because it cannot see R class). This project cannot contain errors in resources because it is a project from other people, and it works on their computers. Also, when I create new android project, it cannot run becauseof the same - no R class.
On OS Windows it sometimes works (after some changes in project files, or re-opening eclipse), but now it is Ubuntu and android sdk for linux.
How to solve this problem?
R is generated. You can delete the whole gen directory and it will get generated again - this is what you should do in your case.
Also you should not ship R to other people (or accept it from other people). This also means not putting it into version control.
Btw, are you getting code from 3rd party in binary form and it includes R? This would not work - compiled libraries on Android can not contain resource files. At least not before SDK r14. http://developer.android.com/guide/developing/projects/index.html#LibraryProjects
Update
R file will not be generated if there are errors in res directory. Delete the gen directory, then right click on the project -> android -> fix android settings.
Please try to check files under /res/ folder, file name should be lowercase, chars in files. It was caused by these resource files.
I had the exact same issue (the R class was missing)
Running Ubuntu 12.04 64-bit and ADT Build: v21.1.0.
Checked Window>Show View>Problems and saw this:
Hint: On 64-bit systems, make sure the 32-bit libraries are installed:
sudo apt-get install ia32-libs
Exited Eclipse/ADT, then installed libraries using terminal:
sudo apt-get install ia32-libs
When Eclipse/ADT re-started, the R class file was generated automatically.
Use Build Project option followed by the cleaning of project.
Or your project java classes might have imported android.R instead of project specific R file.
For this issue you can go with the following step by step method.
1) Remove import android.R;
2) Save the particular java class.
3) Clean the project.
4) Build it again.
Your project will work fine. Just check it out.
SOLUTION:
WOW! This problem has a really EPIC solution! So, what to do? When you install android-sdk for linux, you are unpacking .tgz file which contains different tools. BUT! The tools are executable files, but they haven't executable flag! So, You should do it manually! In the folders tools/ and platform-tools/ it is necessary to do it. In this concrete case: the tool "aapt" generates the R class, so I did:
chmod +x platform-tools/aapt
After that, eclipse COULD generate the R-class.
I hope this message helps someone in the future.
If you have tried all of the above and it doesn't look like you have any errors; check your errors counsel. In my case, in the res directory eclipse automatically generated a menu folder with a main.xml. Because I didn't incorporate a menu; res/menu/main.xml created conflicts. I deleted this and it worked.
res/menu/main.xml:3: error: Error: No resource found that matches the given name (at 'title' with value '#string/action_settings').
May be your installation lacks some of libraries ,,,, run the below code in terminal ...
sudo apt-get install lib32ncurses5 lib32stdc++6 zlib1g:i386 libc6-i386
R is usually automatically generated, but here are some exceptions:
1.) There is an error in the res folder. Resolve by fixing the rogue file.
2.) The project was only partially cleaned. When selecting Project > Clean , select "Clean all projects".

How to install javadoc for Android Compatibility Package?

How to generate custom javadoc for android 1.4 compatibility package?
The reference docs are available online (example), but is there some place where I can get a zip with javadoc available offline?
I suppose using the javadoc would be pretty simple, just a matter of setting the javadoc location for the compatibility jar.
You can generate your javadoc offline on your own from the source code. Just navigate to your android sdk directory then do the following
cd <path_to_android_sdk>/extras/android/compatibility/v4/
mkdir docs
For Windows:
javadoc -d docs -sourcepath src\java -subpackages android.support.v4
For Linux/Mac:
javadoc -d docs -sourcepath src/java -subpackages android.support.v4
This will generate your javadocs for you locally in the docs directory that you just created.
Then in your eclipse android project, go to your project properties where you added the your android-support-v4.jar, edit it's properties and add the the path to the javadocs you just created.
That should work!
ADT 17+ issues:
As some of you have pointed out. There have been issues getting Eclipse to see the attached javadoc for ADT 17+. This is a known issue and a bug has been filed. This is not related to the way you generate the javadoc (as I described above), rather this is an issue with ADT 17+ integrating with Eclipse. Someone has described a workaround and it can be followed here:
http://code.google.com/p/android/issues/detail?id=28801
Problem: If the android-support-v4.jar is in the /libs folder (as the ADT 17+ require) the javadoc is unavailable.
Edit: I have workarounded the problem by linking the offline version of the android javadoc to the android-support-v4.jar. As far as I know it is still not possible to link the online version (http://developer.android.com/reference). Steps:
Download the Documentation for Android SDK from the SDK Manager. You can find it under the latest Android version (4.1)
Link the javadoc folder to your project's folder, in Windows open a console and type: MKLINK /J {PROJECT_PATH}\android_docs {SDK_PATH}\docs\reference
Create the file libs/android-support-v4.jar.properties with this content:
src=android-support-v4.jar
doc=../android_docs
Close the project and reopen it. Clean if necessary.
The javadoc is linked. Check it by going to any Support library class, like android.support.v4.app.FragmentActivity
Thanks to this answer https://stackoverflow.com/a/11579339/933261
The answer by #wnafee is spot on, but if you are using Linux don't forget to use the forward slash character at this location like src/java.
IF YOU'RE ON WINDOWS and get stuck for ages like me, make sure you escape your backsmashes in the properties file, or things will silently fail. (who makes silent failing loaders anyway...)
This this is my properties file:
src=android-support-v4.jar
doc=doc\\android-support-v4_doc
and my dir looks like this:
android-support-v4.docs.zip
android-support-v4.jar
android-support-v4.jar.properties
doc
close project and open, and it all works for me.
I generated this one based on wnafee's answer:
https://dl.dropboxusercontent.com/u/31272696/android-support-v4.zip
I went through all of these solutions and none of them worked. Here is what I did to get it to work:
Navigate to the following folder:
D:\\Android-SDK\android-sdk-windows\extras\android\support\v4
Run the command:
javadoc -d docs -sourcepath src\java -subpackages android.support.v4
In your project's libs directory, create a file called android-support-v4.jar.properties
In the properties file, add the following lines (change the path to match yours):
doc=D:\Program Files\Android-SDK\android-sdk-windows\extras\android\support\v4\docs
src=D:\Program Files\Android-SDK\android-sdk-windows\extras\android\support\v4\src
In Eclipse, bring up the properties dialog for the Build, then navigate to Java Build Path and select the Libraries tab.
Expand the support library. In my case the path is:
D:\Program Files\Android-SDK\android-sdk-windows\extras\android\support\v4
Select Javadoc location. Click on the Edit button and then select the path to the docs. In my case it was:
file:/D:/Program Files/Android-SDK/android-sdk-windows/extras/android/support/v4/docs/
Close everything, including Eclipse and restart. You should now be able to browse docs in your code.

Set classPath for java

I am trying to run the draw9patch.bat from my cmd but it throws the following error.
WARNING: Java not found in your path.
Checking if it's installed in C:\Program Files\Java instead (64-bit).
Checking if it's installed in C:\Program Files\Java instead.
ERROR: No suitable Java found. In order to properly use the Android Developer
Tools, you need a suitable version of Java JDK installed on your system.
We recommend that you install the JDK version of JavaSE, available here:
http://www.oracle.com/technetwork/java/javase/downloads
You can find the complete Android SDK requirements here:
http://developer.android.com/sdk/requirements.html
I have java installed and have also tried changing the classpath from environment variables in the control panel.However it does not seem to solve the problem.What am i doing wrong.
For that you need to set the 'path' environment variable.
Something like this:
path=%path%;c:\program files\java\jdk 1.6\bin
or
the path where you have installed the java.
You may need the swing-worker-1.1.jar, place this in Android-sdk/tools/lib directory.
For people who are looking for solution for Windows 7 (maybe for xp too) and that last answers wasn't the right solution.
If you have problem with running this file, this problem will happens in almost all .bat files in android-sdks/tools files.
Here is what to do and all that batch files will work okay.
I assume that you have downloaded proper JDK so..
Go to folder android-sdks\tools\lib and edit file find_java.bat
Delete all text stored inside and insert into something like that:
set java_exe="C:\Program Files\Java\jre7\bin\java.exe"
if not defined java_exe goto :CheckFailed
:SearchJavaW
set javaw_exe="C:\Program Files\Java\jre7\bin\javaw.exe"
if not exist %javaw_exe% set javaw_exe=%java_exe%
goto :EOF
Please be carefull and put correct path to jre what you have! Here is an example for jre7!

Categories

Resources