R.java is not being generated because eclipse cannot run aapt - android

I use Ubuntu 11.10 and eclipse for Android development. I used to keep the android-sdk in my home folder, but because of low space, I copied it to the hard disk. When I moved the sdk to the hard disk, I did not have permissions to run adb, aapt or other platform tools. So, I edited the /etc/fstab file and added the following line
/dev/sda3 /media/hdisk ntfs-3g defaults 0 0
Now, when I execute the command ls -l | grep "sdk" in the terminal, i get this output
drwxrwxrwx 1 root root 4096 2012-10-20 16:07 android-sdk-linux
So, I have the permissions now, but when I run eclipse, the R.java file is still not generated, but the BuildConfig.java file is generated. I can run aapt from the terminal, but doing it every time I change the code is not practical. Any suggestions?

In case you have a 64bit Linux running, this command may help you:
sudo apt-get install ia32-libs
Had the same issue and that one did the trick. Found here.

Its a very basic check but have you changed the location of the Android SDK within Eclipse?
Preferences -> Android -> SDK Location

This problem seems have to solved itself after restarting my PC about 2-3 times. Thanks for all the help everybody.

Related

Android Studio 2.3.3 stucks when first run

I downloaded Android Studio 2.3.3 for Linux and unzipped the content to /usr/local
then
$ cd android-studio/bin
Edited the file idea.properties and appended a following line to it:
disable.android.first.run=true
Then launched Android Studio:
$ sudo sh studio.sh
Looking in classpath from com.intellij.util.lang.UrlClassLoader#1a7cec2 for /com/sun/jna/linux-x86/libjnidispatch.so
Found library resource at jar:file:/usr/local/android-studio/lib/jna.jar!/com/sun/jna/linux-x86/libjnidispatch.so
Trying /root/.AndroidStudio2.3/system/tmp/jna5562911082428971611.tmp
Found jnidispatch at /root/.AndroidStudio2.3/system/tmp/jna5562911082428971611.tmp
[ 40066] WARN - dea.updater.SdkComponentSource - File /root/.android/repositories.cfg could not be loaded.
^C[18124266] WARN - pl.local.NativeFileWatcherImpl - Watcher terminated with exit code 130
And it will stuck. After long waiting I termited it with Ctrl+C
Try attaching to the process with strace to see what it's doing (for example, waiting on a network or file). Or run it with strace like this:
strace -o foo.log -s1024 -f ./studio.sh
After a while, break it with Ctrl-C and examine the log file for syscalls like open, read, recvmsg.
Alternatively, while it's running, you can attach with a Java profiler to the jvm. For a start, you can launch jconsole or jvisualvm and attach to the Android Studio (it will show as an empty name, with only PID) and view stack traces of individual threads. In jvisualvm you can view the CPU usage sample and click on the hot event and see the stack trace.
Basically you need to find out what the app is trying to access for so long. Most likely some network resource.
I think all your problems happen because you ran as root (sudo) on your first run.
So try to unroot before doing a clean install like I suggest below:
Unroot the installation
cd to the folder where you unzipped Android Studio before
cd ..
Recursively change user and group:
sudo find <thedirname> -print0 | xargs -0 chown <yourusername>:<yourgroupname>
cd ~ or cd to go back to home
Recursively change user and group
sudo find .Android* -print0 | xargs -0 chown <yourusername>:<yourgroupname>
(I sudo because you've used root user previously).
Recursively change user and group
sudo find Android* -print0 | xargs -0 chown <yourusername>:<yourgroupname>
cd into the unzipped directory. Do chmod +x studio.sh.
Start Android Studio ./studio.sh
If it didn't help, do a:
Clean install
Download and unzip a fresh copy of Android Studio. I suggest version 3, it's pre released, but stable. It doesn't matter where you put it.
I believe you have Java installed, but make sure you have Java 8 as the default one: in command line: java -version, make sure it's 1.8.
Move any old installations out of the way, in case they are corrupt:
sudo mv ~/.Android* ~/tmp/
sudo mv ~/Android ~/tmp/
should do the trick. (I sudo because you've used root user previously).
cd into the unzipped directory. Do chmod +x studio.sh.
Start Android Studio ./studio.sh
Make sure all the files are owned by your username, and group as well.
I took some information from:
Stuck at “.android/repositories.cfg could not be loaded.”
Installing Android Studio in Ubuntu 14.04 64-Bit .android/repositories.cfg could not be loaded
The answers collectively say that:
Android Studio will run fine without repositories.cfg.
You can remove this warning by putting the following into repositories.cfg:
### User Sources for Android SDK Manager
count=0
After waiting some time it eventually goes beyond that step.
Patience is the key.
So, try waiting a little bit more. It always helps.
This is common. On your first run the gradle files are needed to be downloaded and installed in background. It's about 90 MB in size and even if your internet speed is high, the gradle servers may be slow taking it to maximum of 1 or 2 hours in the worst case. So open Android Studio and wait until it opens. Hope it helps.
I've found a potientaly useful link from AskUbuntu, the guy suggested creating an empty file called repositories.cfg. And that solved it.
Ref: https://askubuntu.com/questions/885658/android-sdk-repositories-cfg-could-not-be-loaded
Just remove /root/.AndroidStudio2.3 and /root/.android (after making a backup)
Maybe it has something to do with the script looking at the root location. Have you tried using chown on the unzipped content directory?
Try this to install
Download the studio
Extract to home
go to android-studio/bin/
Mouse right click than open terminal
type ./studio than press enter
now it will start to install studio. If you installing first time than It will download some files of SDK. and if you have already downloaded SDK than you can cancel download and set you SDK path from the setting from right bottom corner.
try creating repositories.cfg -- Because I see it as warning. Let's see what happens after that!
touch ~/.android/repositories.cfg /* Linux */
Extract your downloaded Android Studio setup zip file to your /home/<user_name> directory and in terminal follow the below commands
$ sudo chmod +x studio.sh
And hit enter
Now run the following command
$ ./studio.sh
And wait for some time to download the required libraries.

android aapt doesn't work on arch linux

when ever I run the cordova/build, I get following ERROR:
Execute failed: java.io.IOException: Cannot run program "../android-studio/sdk/build-tools/android-4.4W/aapt"
what should I do?
I moved my Android Developer Tools (ADT) folder from Ubuntu's partition to Linux Mint's partition, but accidentally put in inside my web server's root folder and the permission of ADT's folders were set to 755, the files were set to 644 by my shell script to rebuild the permissions for my new web server.
After I moved ADT to my home folder and started using Android Studio, I got this problem.
sudo chown $USER:$USER -R /home/myusername/my-adt-folder
doesn't help.
GNU C Library was already installed by default. Not sure why it is related to this problem.
I decided to set 777 permission to ADT and it worked.
sudo chmod 777 -R /home/myusername/my-adt-folder
That's it.
It seems another system user in the system needs to access to android-4.4W/aapt file.
I solved it by installing lib32-glibc.
https://www.archlinux.org/packages/multilib/x86_64/lib32-glibc/
If you just want aapt on Arch without the overhead/hassle of setting up ADT then you can try the solution that I presented on the Android Enthusiasts site here.

Gradle, Android and the ANDROID_HOME SDK location

edit: (aug-2016)
That question is from November 2013 (while Android Studio was still in Developer Preview mode),
Currently (AS v2.2, Aug-2016) during instalation AS asks to choose the SDK folder (or install on their default) and it automatically applies to which ever project you're opening.
That means any possible workaround or fix is irrelevant as the issue is not reproducible anymore.
original question:
we have this project with several modules that is already configured and executes correctly on another developer PC using a wrapper. I cloned the complete git submodules into my machine.
Below it's a directly print of my command line:
$ ./gradlew
FAILURE: Build failed with an exception.
* Where:
Build file '/home/budius/project_name/ActionBar-PullToRefresh/library/build.gradle' line: 1
* What went wrong:
A problem occurred evaluating project ':ActionBar-PullToRefresh:library'.
> SDK location not found. Define location with sdk.dir in the local.properties file or with an ANDROID_HOME environment variable.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED
Total time: 6.378 secs
$ echo $ANDROID_HOME
/home/budius/Applications/android-studio/sdk
$
so, as you can see the ANDROID_HOME is there. What else do they want? What's wrong here.
running on Ubuntu 13.04
edit:
I already created a local.properties file with sdk.dir=<path> on the project root and it works. But that makes the code harder to port across systems n build server, so the question is still open.
Anyone knows why the ANDROID_HOME is not working and what to do to make it work?
In /my_current_project/, I created a file called local.properties and put inside:
sdk.dir=/my_current_path_to/sdk
In the console I need to do:
set ANDROID_HOME=/my_current_path_to/sdk
On OSX, IntelliJ won't pick up the environment variables you set in your .bash_profile or .bash_rc etc...
Try this, substituting the value of your own sdk location:
launchctl setenv ANDROID_HOME /usr/local/opt/android-sdk
Then restart IntelliJ and Bob's your uncle.
Here is a reference to the problem, stated more generally:
https://emmanuelbernard.com/blog/2012/05/09/setting-global-variables-intellij/
In my case settings.gradle was missing.
Save the file and put it at the top level folder in your project, even you can copy from another project too.
Screenshot reference:
Hope this would save your time.
This works for me:
$ export ANDROID_HOME=/path_to_sdk/
$ ./gradlew
The Android Gradle plugin is still in beta and this may simply be a bug. For me, setting ANDROID_HOME works, but we may be on different versions (please try again with the most recent version and let me know if it works or not).
It's also worth setting the environment variable ANDROID_SDK as well as ANDROID_HOME.
I have seen issues with this on some machines, so we do create local.properties in those cases - I have also noticed that the latest version of Android Studio will create this file for you and fill in the sdk.dir property.
Note that you shouldn't check local.properties into version control, we have added it to our gitignore so that it doesn't interfere with porting the code across systems which you rightfully identified as a potential problem.
For whatever reason, the gradle script is not picking up the value of ANDROID_HOME from the environment. Try specifying it on the command line explicitly
$ ANDROID_HOME=<sdk location> ./gradlew
I faced the same issue, though I had local.properties file in my main module, and ANDROID_HOME environment variable set at system level.
What fixed this problem was when I copied the local.properties file which was in my main project module to the root of the whole project (i.e the directory parent to your main module)
Try copying the local.properties file inside modules and the root directory. Should work.
I came across the same problem when opening a cloned git repository. The local.properties file is automatically added to the .gitignore file as it is specific to the build environment of each machine and is therefore not part of the repo.
The solution is to import the project instead of just opening it after you have cloned it from git, this forces android studio to create the local.properties file specific to your machine:
File >> Import Project >>
MAC OSX:
Open up Terminal and edit the file:
~/.bash_profile
to add:
export ANDROID_HOME=~/Library/Android/sdk
export PATH=${PATH}:${ANDROID_HOME}/tools
export PATH=${PATH}:${ANDROID_HOME}/platform-tools
Run:
source ~/.bash_profile
Restart the Terminal and Android Studio
How to do it on MAC OSX:
1) Open up Terminal, and Edit: vi ~/.bash_profile If there is no file there, just add it.
2) Add (Change to YOUR USER NAME and add this):
#Java var home:
JAVA_HOME="/usr/libexec/java_home"
ANDROID_HOME="/Users/<YOUR USER NAME>/Library/Android/sdk"
3) Run source ~/.bash_profile.
4) Run echo $JAVA_HOME; echo $ANDROID_HOME;
5) If your output is:
/usr/libexec/java_home
/Users/<YOUR USER NAME>/Library/Android/sdk
So you are good.
and RESTART android studio!
And,
Make sure that you have java :)
java -version
And gradle :)
gradle --version
Copy the local.properties to root folder and run again.
This worked for me (Ubuntu):
Add ANDROID_HOME=/path/to/android-sdk to /etc/environment.
Reboot.
in windows, I set ANDROID_HOME=E:\android\adt-bundle-windows-x86_64-20131030\sdk
Then it works as expect.
When in Linux, you need to set sdk.dir.
The script uses two different variables.
I have the same problem, seems the sample code can not find the android environment, instead to try to fix that I just remove the sample code from settings.gradle and then the installation goes fine.
after that just import the project in eclipse and that's all :)
In Linux, try to run studio.sh from a terminal and set the ANDROID_HOME in this terminal. This worked for me.
If you are using windows plantform, please try run Android Studio as Administrator
Just delete the sdk.dir inside the local.preoperties file and set the ANDROID_HOME environment variable . It worked for me.
export ANDROID_HOME=/xxx/xxx/ in shell, then use it by System.env.ANDROID_HOME in gradle file.
PS: don't forget the 'export' keywords to make the ANDROID_HOME global.
Your local.properties file might be missing. If so add a file named 'local.properties' inside /local.properties and provide the sdk location as following.
sdk.dir=C:\Users\\AppData\Local\Android\Sdk
I have set the ANDROID_HOME = [PATH_OF_MY_ANDROID_SDK] to my environment variable. That solution works for me.
I have just solved the exact same issue by adding the ANDROID_HOME as a system wide variable.
In Ubuntu it should be in /etc/profile or in a shell script file in /etc/profile.d/
Then logout and login again, now Gradle should recognize the ANDROID_HOME variable.
I came across a similar problem. Somehow, I did not have a build folder in my project. By copying this folder from another project to my project I was having an issue with, this fixed this problem.
Installing Build-Tools 23.0.1 instead of 23.0.2 fixed this issue for me.
solutions:
1 add "sdk.dir=path_of_sdk"
2 execute gradlew with evn variable like following:
$ANDROID_HOME=path_of_sdk ./gradlw
You said that versioning local.properties creates problems for you. I've hacked together a script which uses android command line tool to refresh the local.properties file across the machines that are involved in the production. The android update project command, besides the local.properties produces a lot of unwanted trash (at least for me) which is the reason for all those rm commands at the end of the script.
#!/bin/bash
scname="$0"
echo "${scname}: updating local properties..."
ln -fs src/main/AndroidManifest.xml
android update project -t 24 -p "$(pwd)"
echo "${scname}: ...done"
echo "${scname}: removing android update project junk ..."
rm -v project.properties
rm -v build.xml
rm -v proguard-project.txt
rm -v AndroidManifest.xml
echo "${scname}: ...done"
This script is the first thing we run on any new machine where we code. It has to be run in the root project directory. Of course, android studio may have a GUI way of dealing with this, but I wouldn't know as I use a different editor. I also can't claim that the solution is general, but it "Works For Me" (tm).
I have faced with the same issue on Ubuntu(both local.properties and ANDROID_HOME was added), but build fail persisted. So workaround is to
add following lines
export ANDROID_HOME=/home/<user>/Android/Sdk
export PATH=$PATH:/home/<user>/Android/Sdk/tools
directly to the studio.sh script (inside /usr/local/android-studio/bin)
Maybe it will be helpful.
i encountered the same error but in my case i was cloning a project, the cloned project was built with Android API 22 which i did not install at the time(i had API 24 and 25 installed)........so i had to download the sdk tools for API 22
For Windows:
Add ANDROID_HOME to the Environment Variables:
ANDROID_HOME = C:/Users/YOUR_USERNAME/AppData/Local/Android/sdk
Add %ANDROID_HOME%\platform-tools to the PATH.
On my system (Ubuntu 20.04 after two version upgrades from 19.04) the symptoms were as if gradle (4.4.1 installed from APT repos) ignored ANDROID_HOME environment variable, while picking up the sdk.dir value from local.properties if I created one.
The reason appeared to have been that java command referred to openjdk version "11.0.7". After I installed openjdk-8-jdk package and did update-alternatives --config java to make the default java be version 8 ("1.8.0_252"), gradle started working as expected.
My issue was that directory did not exist. The env vars were set correctly, but the underlying directory did not exist. After opening AS the first time and having it create the directory, everything worked.
echo $ANDROID_HOME
/Users/x/Library/Android/sdk
$ echo $ANDROID_SDK_ROOT
/Users/x/Library/Android/sdk
$ cd $ANDROID_HOME
-bash: cd: /Users/x/Library/Android/sdk: No such file or directory

android Failed to start emulator:Cannot run program

I have installed android SDK and android eclipse plugin successfully on Ubuntu.
Every thing was working fine until I removed Ubuntu and installed Linux Mint.
I installed the SDK again and used the same eclipse copy I was using on Ubuntu but now all the android applications contain errors and I can not start the emulator.
When starting the emulator this message appears
Starting emulator for AVD 'test' Failed to start emulator: Cannot run program "/home/anas/android//tools/emulator": error=2, No such file or directory
While the android SDK is installed in the specified path and the file (emulator) is exists in the same path.
Also all my applications contains the same error R can not be resolved to a variable
What is the problem here?
Installed on Ubuntu successfully.
but not running avd
If you're running a 64-bit system, you need to install ia32-libs
sudo apt-get install ia32-libs
R can not be resolved to a variable
This can be due to following Reason
class is not the part of that package add proper package
not properly defined in manifest file class path define it properly
clear and run the avd it will work
If cmd from fist comment doesn't work like in my case (64bit Crunchbang) then you may also try with :
sudo aptitude install ia32-libs lib32ncurses5 lib32stdc++6
I solved it doing a backup of the "emulator" and creating a symbolic link to the correct emulator:
mv emulator emulator_bup
ln -s emulator64-arm emulator
I used the command-line tool android (android avd), and used Tools->Manage SDK to install 64 bit emulators. I then mv'ed emulator to emulator.old, and emulator64-arm to emulator. Now the AVD starts up.
You do not need install packages any more!
In directory tools, there are many types of emulator, while my computer works with emulator64-arm! My system is Linux Mint 16 amd64! Good luck!
./emulator64-arm #yxphone -sdcard yxsd -scale 0.8
Like you have written the specified path and the files are exists in the same path, but i suggest to check that one more time.
and like you are getting R cannot be resolved to a variable, do not worry:
Reasons:
Check Package name in Manifest File
If you are already getting something like this: import com.version.bajrang.january.R;
so first of all try to change package name here, or secondly just delete this line and
clean your program
If you are not getting something like: import com.version.bajrang.january.R;
then add import packagename.R;
I believe that you will get your answer.....
It looks like your SDK path in eclipse has a mistake:
Cannot run program "/home/anas/android//tools/emulator"
That double "//" may be the problem. Check in Eclipse: Window -> Preferences -> Android. There should be a field there pointing the SDK Location. Edit it.
Check your path : /home/anas/android/ to see if it really is where you put your SDK . If not repeat these steps to have it
The missing R resource message is a compile error right? Then in this case your emulator should not be the problem. However, if your SDK path is incorrect like I suspect, then .. you can expect this compile error along with any other android libraries import
This is sorted by running this on Ubuntu.
sudo cp ~/Android/Sdk/platform-tools/adb /usr/bin/adb
Refer this: Can't connect to emulator through ADB genymotion

Javah missing after JDK install (Linux)

I'm trying to setup Android development with Eclipse (Indigo), on Fedora17.
Almost everything seems to work, just the javah is missing, to build the C headers with, for native (NDK / JNI) modules.
On my windows install of the tool chain it was in the same folder javac was in, but this is not the case on the Linux machine.
I previously installed Oracle's JDK1.7, found out that it's to new for something else I wanted to do (but also there, no javah), uninstalled it, now JDK1.6 is installed.
What might be wrong?
In linux machines, JavaH is normally located in /usr/bin/javah.
If you try to find this file with locate, it is normally a good idea to run before updatedb, since the database is not updated unless this command is run either by the user or a cron job. You could try finding the file with find / |grep javah
P.S. Sorry to post this as an asnwer. I suppose the corret way to go would have been a comment, but still don't have enough reputation to post a comment
This tool has been removed from the JDK
https://openjdk.java.net/jeps/313
Try gjavah rather than javah?
It turns out that javah link is not created during JDK install. You have to create it manually:
Check where is installed java:
$ ls -l `which java`
lrwxrwxrwx root root 26 15 juil. 02:05 /usr/bin/java -> /usr/java/default/bin/java
Create the symlink in the same directory:
$ su
# cd /usr/bin
# ln -s /usr/java/default/bin/javah

Categories

Resources