How to configure javah tool in Eclipse [duplicate] - android

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")

Related

Where is build.xml in android

I m making an app which shares its file from assets folder and I m sharing an xml file to other app it gives me this exception
java.io.FileNotFoundException: This file can not be opened as a file descriptor; it is probably compressed
I got this TUTORIAL but at point number 7 it says that "ADD THIS SECTION TO THE END OF build.xml" so where can I get this build.xml??
And any way around to resolve this exception??
I m using MAC OS X
Run android update project -p ..., where the ... is the path to the project. This will create or update the build.xml and related command-line build files. This assumes that your SDK's tools/ directory in your PATH; otherwise, you will need to fully-qualify the path to the android command.I hope it will helps you .
Follow this Procedure To Use build.xml
Go to your Android SDK installation, and open the file "tools/ant/build.xml", copy the complete "test" target and paste it in the "build.xml" of the test project, before the import of build.xml, so before the comment starting with "Import the actual build file". There is more information on how to customize targets in that comment.
If its Confusing Follow this for Complete Ant....
Hope You understand..

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 run "android.bat sdk" in Windows 7

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.

New android SDK 17 issue in my app?

Today i was update my android sdk to new android adk-17 .
i am facing some problems in this, that is unable to show AddMob in my app, if i remove addmob in the code able to run the app without any errors otherwise not. what is the solution for this, is this bug in new sdk.
this is the Logcat information
Caused by: java.lang.ClassNotFoundException: com.google.ads.AdView in loader
dalvik.system.PathClassLoader[/data/app/com.veritra.iflipout-1.apk]
Maybe the ADK update has messed-up with your project's build-path.
Try removing the admob JAR and add it again to your libs folder, add it to your Build Path and do a Clean Project.
Anyway it's hard to help you without more details on the error you encounter.
EDIT following poster's comment about not having a libs folder:
You should try this:
Remove all references to the AdMob JAR in your project -> your code should not build without error anymore
Create à libs folder at the root of your project
Copy the AdMob JAR into the libs folder
Make sure this AdMob JAR is in your Build Path (this will allow your code to build wihtout error)
(If still not running OK) Right click your project > Android Tools > Fix Project Properties
The 'problem' here is that the SDK is a lot more strict about the libraries. If you do not check the library as 'exported' in eclipse, it is not added to your APK, leading to this nasty class not found exception. You should mark your libraries as exported.
Project Properties | Java Build Path | Order and Export
when I updated my SDK it was total mess. Well, the only I had to change was the PATH in Environment Variables.
http://developer.android.com/sdk/installing.html :
Adding both tools/ and platform-tools/ to your PATH lets you run command line tools without needing to supply the full path to the tool directories. Depending on your operating system, you can include these directories in your PATH in the following way:
On Windows, right-click on My Computer, and select Properties. Under the Advanced tab, hit the Environment Variables button, and in the dialog that comes up, double-click on Path (under System Variables). Add the full path to the tools/ and platform-tools/ directories to the path.
On Linux, edit your ~/.bash_profile or ~/.bashrc file. Look for a line that sets the PATH environment variable and add the full path to the tools/ and platform-tools/ directories to it. If you don't see a line setting the path, you can add one:
export PATH=${PATH}:/tools:/platform-tools
On a Mac OS X, look in your home directory for .bash_profile and proceed as for Linux. You can create the .bash_profile if you don't already have one.

Using Proguard for Android in Eclipse got Error

I have taken a fresh install of Eclipse and all the latest Android tools and want to use Proguard on existing project, but for now I have created a new blank one.
I have added a proguard.cfg file to my project
added proguard.config=proguard.cfg to my default.properties
Now when I try to export I get the following error
[2010-12-12 10:36:35 - ApplicationTest] Proguard returned with error code 1. See console
[2010-12-12 10:36:35 - ApplicationTest] 'C:\Program' is not recognized as an internal or external command,
[2010-12-12 10:36:35 - ApplicationTest] operable program or batch file.
[2010-12-12 10:36:35 - ApplicationTest] '-jar' is not recognized as an internal or external command,
[2010-12-12 10:36:35 - ApplicationTest] operable program or batch file.
I know it means there is a filepath setup incorrectly, question is where the heck is as I have looked through the general properties and project properties and can't see any reference to proguard or obfuscation so am stuck on what to change
Any help appreciated.
You need to define your Android SDK path without spaces. Copy&Paste from this answer by Mark:
Proguard error: Expecting class path seperator - not sure where I need to put a path in quotes
Yep, that worked for me. To put it
specifically:
In Eclipse: Window > Preferences >
Android > SDK Location
use something like
c:\Progra~1\android-sdk (or maybe c:\Progra~2\android-sdk on 64bit)
For me the path is "c:\Progra~1\Android\android-sdk-windows"
According to comments posted by a Google Engineer in thread here:
http://groups.google.com/group/android-developers/browse_thread/thread/19b96902fc20cede
*.bat file shipped with ProGuard doesn't support paths with spaces.
Having Java and Android SDK installed on paths without spaces doesn't solve the problem completely. Things can go wrong if path to eclipse workspace, temp folder or some of external JAR files contains spaces as well.
I was too lazy to re-install everything so my workaround involves making junction points on a file system.
I just reinstalled JAVA and ANDROID in the root directory instead of under their default paths in program files and it all worked
Is there not a way to specify the direct paths ourselves to the Java and Android SDK in the proguard config file?
This problem looks to be fixed in ADT 12. The following change in main_rules.xml solves the problem and should be included in ADT 12: https://review.source.android.com/#change,22791.
I can verify that downloading the fixed version and replacing the copy that comes with the sdk at your_sdk_path/tools/ant fixes this issue.
OK , now i found one way to fix this problem
1, set up the "PROGUARD_HOME" EVN PATH to \tools\proguard
2, restart eclipse
3, now it work fine!
I changed the SDK paths to the 8.3 format and changed the proguard.jar folder in proguard.bat to the 8.3 format and now all is working again!

Categories

Resources