Refer to:
How can I set up Vim for Android development?.
Autocompletion of vim (omnicomplete) is powerful tool of vim,
but there was no tags of android library...,
how do i set my vim for android development?
The most powerful way is using eclim which is an interface to eclipse.
Pressing C-x C-u in insert mode shows the auto-completion popup.
The drawback is that you have to install the whole eclipse IDE.
If you prefer a slim solution you can use javacomplete. Just set it up as told in the instructions. Then you can use C-x C-o to open the auto-completion popup.
To get completion of android classes just add it temporarily to your CLASSPATH environment variable e.g. by starting vim via
CLASSPATH=/opt/android-sdk/platforms/android-2.2/android.jar:$CLASSPATH vim
You might also be interested in Vim JDE a quiet good Java IDE for vim.
The issue when setting a CLASSPATH with javacomplete is that your tying yourself to a specific target platform, target '9' in buergi's example.
I wrote a small plugin that reads current target and set an appropriate CLASSPATH for current project's target on after 'java' filetype is set.
In order to use it you have to call vim from the project's main directory, or start it whenever you want and then change the working directory to project's root.
Hope it helps.
Look github for android plugins, there are a few.
I recommend this plugin: https://github.com/hsanson/vim-android, and yes I wrote it.
Related
One developer on my team has some setting in Android Studio that replaces the distributionUrl entry in gradle/wrapper/gradle-wrapper.properties to use the gradle-###-all.zip, while my Android Studio changes it back to gradle-###-bin.zip.
Basically, my diff always looks like:
-distributionUrl=https\://services.gradle.org/distributions/gradle-1.12-all.zip
+distributionUrl=https\://services.gradle.org/distributions/gradle-1.12-bin.zip
This is annoying. What setting is it, and how do I change it?
gradle-1.12-all.zip file will have binaries, sources, and documentation.
gradle-1.12-bin.zip will have only binaries(That should be enough as you don't need any samples/docs)
If you want to know about gradle wrapper, please check this
http://www.gradle.org/docs/current/userguide/gradle_wrapper.html
If you and the other developer want a uniform experience, place this code in your build.gradle file
wrapper {
distributionType = Wrapper.DistributionType.ALL
}
This will make ./gradlew wrapper --gradle-version 5.6 automatically append -all instead of -bin
For build.gradle.kts:
tasks.wrapper {
distributionType = Wrapper.DistributionType.ALL
}
Like #San said, -all will have binaries, sources, and documentation, while -bin will just have the binaries.
From what I've seen Android Studio recommends to use gradle-*-all.zip and even provides a "quick fix" to change that. On the other hand, the command ./gradlew wrapper sets up the wrapper using gradle-*-bin.zip, overwriting the previous setting. Make sure nobody is calling "./gradlew wrapper" automatically.
The difference is that the -bin version contains only the runtime and no sample code and documentation. 1
It actually makes sense to go for the -bin version: it is smaller and you're unlikely to need the -all version unless you're debugging Gradle scripts. For this reason, the lint warning to go for the -all version has been removed. Also, new projects are generated with the -bin version by default.
There is a ticket to let IntelliJ download the sources when you need them (after which there really isn't a reason for the -all version), but it hasn't been implemented yet.
I do have a multi-module project with a library project in a different root path. As illustration you can imagine something like this:
/projects_home/projects/app_root
|--app/
| |--build.gradle
|--build.gradle
|--settings.gradle
/libraries_home/libraries
|--libA
|--build.gradle
In my settings.gradle file I am able to set the absolute path to the library project utilizing the projectDir attribute. This works just fine within the console as well as with Android Studio.
But if I try to use an environment variable it stops working with Android Studio. The settings.gradle for the example above would look like this:
include ':app'
include ':libA'
project(':libA').projectDir = new File("$System.env.LIB_ROOT", '/libraries/libA')
If I build with the graddle wrapper from the console, it still works. But AS stops working with the following error msg:
Gradle 'app' project refresh failed:
Configuration with name 'default' not found.
If I unset the environment variable, the build on console fails with the same msg:
* What went wrong:
A problem occurred configuring project ':app'.
> Configuration with name 'default' not found.
Therefore I guess that AS is somehow not be able to access the environment variables set with my ~/.bashrc
Does somebody of you maybe know a way how I can make AS aware of my environment?
Android Studio does read the environment variables. You can prove it by launching Android Studio from the shell in which those env. variables being specified instead of from X-window dash board.
The reason you did not have those variables is the X-window environment you were using did not read $HOME/.bashrc which contained those variables. This makes sense because bashrc is for Bash not X.
Assuming you are using GNOME or Unity, to launch Android Studio with those environment variables being specified, just modify the .desktop file of Android Studio (e.g. ~/.local/share/applications/android-studio.desktop):
Find this line:
Exec="/home/username/tools/android/android-studio/bin/studio.sh" %f
Change it to:
Exec=env LIB_ROOT=/libraries_home "/home/username/tools/android/android-studio/bin/studio.sh" %f
Note:
This modification just prepend env LIB_ROOT=/libraries_home to the original command. You must replace username with your own user name.
Update
If you have any questions, please leave a comment instead of editing the answer directly.
On Macs, Android Studio does not read environment variables for use in Gradle apparently. I believe this is the cause for confusion in the answers here - maybe it does on Windows.
In order to get Android Studio to read environment variables, I run the application from the command line:
> /Applications/Android\ Studio.app/Contents/MacOS/studio
The other answers here offer solutions other than using environment variables. For my situation, I'm using a library I didn't write that requires the use of an environment variable, and I'd rather not edit their code so it's easier to update later.
EDIT: And, I have a dock icon to launch Android Studio this way:
OSX: Add Dock icon for dedicated Terminal command explains how.
Android Studio doesn't read environment variables, so this approach won't work. Also, using the projectDir scheme in settings.gradle will probably cause problems. Android Studio has a limitation that all of its modules need to be located underneath the project root. If you have libraries that are used in multiple projects and they can't be placed under a single project root, the best advice is to have them publish JARs or AARs to a local Maven repository that individual projects can pick up.
Despite the answer from Scott Barta is correct, I realized there is a way to solve my problem and wan't to share this in case somebody else has the same requirement.
I am now using the gradle.properties file do define and use gradle properties instead of system properties. The documentation of this feature can be fined in the user guide
The solution to my original question now looks like this:
$USER_HOME/.gradle/gradle.properties:
LIB_ROOT=/libraries_home
The settings.gradle file has to be modified to use the gradle property instead of the system property:
include ':app'
include ':libA'
project(':libA').projectDir = new File(LIB_ROOT, '/libraries/libA')
This works fine for me, headless as well as with AS.
Some more words regarding the fact that I am working with modules which are not placed underneath one project root. Till now it looks like AS is not complaining about this. But I just started working with this structure and it may be that I will run into problems later. What I like about this is the more flat representation in AS which is more like I am used to have it with Eclipse.
What is also described in the user guide, is to set system properties with the gradle.properties file. I tried this also, but I did run into the same problems with AS using environment variables.
It works for me with the following steps:
Set your variable in Windows
Reboot
reach it in gradle build: System.env.MYVARIABLE
I faced the same issue in apple laptop after the Android Studio Bumblebee update. This seems to be happening due to some permission issue with the Android Studio.
The workaround is to add missing flag:
chmod +x /Applications/Android\ Studio.app/Contents/bin/printenv
You can check this issue tracker for more details.
You can set environment variable by appending:
-DYOUR_VARIABLE=variable_value
to ~/Library/Preferences/AndroidStudioX.X/studio.vmoptions that you can open by selecting Help -> Edit Custom VM Options... from Android Studio menu.
And then you can use it like:
System.env.YOUR_VARIABLE
in build.gradle or settings.gradle.
MAC OS Update
I confirm that I have Environmental Variables working on Mac OS Catalina
You just need to set it in the shell you are using. I was using zsh, and was trying to set ~/.bash_profile, so it wasn't working.
Example:
ZSH Profile
I want to edit the reformating which comes with the official Android ADT in eclipse, is this possible?
I want, for example, remove the break after a long class decleration.
I have the official AOSP source on my computer and found a the android-formatting.xml, is it the same as in the Android ADT? If yes, How can I override the ADT formatting and can use my custom file which I can import (a modified android-formatting.xml).
I want, for example, remove the break after a long class decleration.
I am not aware that Android specifies any formatting for Java classes. That is handled by Eclipse and can be modified from within Eclipse itself (Preferences > Java > Code Style > Formatter).
If I change some code, save, and Run, it runs the last version of the program, not what I just saved. The only way I can make it update is if I Clean the project, Build the project, and then Run the project. Is there some way to avoid this tedium?
I spent some time create two dummy projects (one Android and one Java) and have a play with it, and finally come up with a workaround which is not used very often but able to solve your requirements.
First, I will explain your question a bit more (based on my understanding and what I have tried) so that other people can have a more clear understand about what is happened here.
According to the conversation in comments:
could you tell me what you have in following setting: project->properties->Builder ? – Sudar Nimalan
#SudarNimalan: I am not sure this is what you are asking, but: there's text that says "Configure the builders for this project", and under it is a single option, "Java builder", which is selected (checked). – shino
for android project, there should be, "Android Resource Manager", "Android Pre Compiler", "Java Builder", "Android Package Builder" in this order, chould you add those and try? – Sudar Nimalan
#SudarNimalan: I owe you an apology; I do have those four components. My "project" is split into 4 projects - "core", "core-android", "core-desktop", and "core-html". It's a little weird because I set it up with the libGDX project setup UI, and I was looking at the 'core' project when I answered your question. My 'core-android' project has all four (in that order), and it is the one that has the problem in my question. – shino
Scenario:
You have 4 project:
core: a regular java project (common pure java code here)
core-android: an Android application project.
core-desktop: not related to question so ignored.
core-html: not related to question so ignored.
The core-android project has dependency on core project, by adding core to core-android's build path (Properties -> Java Build Path -> Projects -> Add ...) and export list (Properties -> Java Build Path -> Order and Export).
Problem (Not Really):
Change some code in core and save it, run core-android, eclipse install last compiled apk, not the new one with change.
Reason:
The is the expected behavior, the way you used to reference core project in core-android only create a weak link (or something sort of) between core and core-android, the core-andorid's auto-build script doesn't aware any changes made in core. You have to clean the project (only need clean core-android project) so that Eclipse can delete the existing apk (under bin directory) and re-generate the apk (with the latest code changes from core).
See Xav's comments below, Android SDK tools should aware changes from plain Java project under project build path, and it does not behaviour this feature normally at the moment.
Note that if core is an Android Library project, then there is no problem and your core-android project will aware any changes in core project (java code, android resource and etc), if core is only used in core-android, this could also be a workaround: turn Java project core into Android library project.
Workaround (Eclipse Link Source):
There is another way (not commonly used) for adding soft link between projects:
First, you need remove core project from core-android's build path, this will also remove it from Export and Order list.
Right click core-android, choose Build Path -> Link Source ... Add ../core/src as Linked Folder Location and src-lib1 as Folder Name,see screen screen in the end.
This create a symbolic link src-lib1 under core-android in Package Explorer windows point to core's src foder, in the file system, you still have two separate project folder. Now if you change some code in core and run core-android, Eclipse will build and install latest apk. No need to clean core-android project.
Link Source Window:
Final look in Package Explorer:
You should always consider the normal approach as first option, after all, manual clean project is not a big deal compare to the unusual approach I described above.
Please follow this steps..
1. Project--> Build Automatically been checked??
2. Please following setting: project->properties->Builder like that?
Check below image.
And Also Check Below Settings.
Also Check Below Image
IF problem continues then please Update your ADT & SDK.
Hope it works for you .
Navigate to Windows->Preferences->Android->Build. Make sure that the checkbox "Skip packaging and dexing..." is NOT checked.
The Problem is the In your Eclipse, go to Project Properties - Builder, There is one CheckBox with AndroidPackageBuilder that is required to be Checked True. Now everytime you will do any changes in you project that will be reflected in your build and the Compiler will never say that
"Application Already Deployed, No need to Reinstall"
This will work evenif you dont have selected Build Automatically, Because everytime you run by clicking Run icon or Ctrl+F11 that will first Build the Project and Then Run it. So The requirement is just to Enable the Android Package Builder
You won't believe how easy and silly is the solution
On Eclipse,
go to Window-Prefences->run/debug ->launching
And then, on Save required dirty editors before launching :
choose the Prompt option,
Apply and OK
I am new to Android. I am working in the Windows OS with the Eclipse IDE. My simple application has a spinner that populates a list from database column. When I click on the spinner Class, the file Editor says that source not found and the android.jar has no source attachment.
I downloaded the source code and placed it in this location:
android-sdk-windows\platforms\android-8
Then, I attached this source by these steps:
right click the project => build path=> configure build path=> libraries => source attachment => give the path of the source code downloaded.
But, I didn't get any solution for my debug. Again, when clicking on the spinner it opens the debug that android.jar has no source attachment.
This is now really easy!
Go to Window->Android SDK Manager and install "Sources for Android SDK".
Now try to control-click some Android identify, you will get the usual "no source attached" page. Click "Attach Source" and get the option to select an external folder.
Now browse to /home/me/android-sdks/sources/android-16 (or wherever your SDK is installed; this is the default), and hit ok.
It should think for a moment and then display the source! Yeay!
Unless you need older API sources, you are probably better served by Timmmm's answer. If you do need sources older than 14, read on...
In Eclipse simply go to
Help -> Install New Software
then add update site
http://adt-addons.googlecode.com/svn/trunk/source/com.android.ide.eclipse.source.update/
and go through the motions to install it.
This will happily provide sources for all installed API versions and works very well for me.
Some more documentation is here
http://code.google.com/p/adt-addons/
look for the heading Android Sources
If adding folder android-sdks/sources/android-17 as external source doesn't work (as in my case) you can try to create folder android-sdks/platforms/android-17/sources/android-17 copy sources to it and restart eclipse (I have eclipse Juno Service Release 1). Only this way works for me.
Steps to do this for android-17:
Go to the adroid-sdk install folder, for me it's d:\ws\android-sdks\
Copy android-17 sources folder from android-sdks\sources\android-17\ to the android-sdks\platforms\android-17\sources\ (your have to create folder sources here manually) folder so the final path to the sources must be the: android-sdks\platforms\android-17\sources\android-17\
restart the eclipse, it must automatically attach sources for android-17
UPD: the same solution with symlinks:
Windows Vista+ (thanks #saleemrashid1 for mentioning mklink in comments):
1. cd platforms\android-17
2. mklink /D "sources\android-17" "..\..\..\sources\android-17"
For Unix-base OSes (#Joe comment):
it works fine to create the directory and symlink "sources/android-XX"
to "../../../sources/android-XX":
mkdir platforms/android-19/sources &&
ln -s ../../../sources/android-19 platforms/android-19/sources/android-19.
To attach source code for android.jar, you may follow the tutorial at the link below:
http://android.opensourceror.org/2010/01/18/android-source/
Make sure to choose the correct platform version.
If you meet difficutly with spinner, try to get the sample code and see how it works:
http://developer.android.com/resources/samples/get.html
Good luck. :)
Update
This answer is quite out of date, please consider other answers.
What worked for me follows the answer found in Murach's Android Programming. I got stuck trying to debug and tried to work it out for about 3 hours before turning to the next page (literally) where it said "Sometimes Eclipse will display a source not found message because...." (-headdesk-)
My solution was to turn on Step Filtering and add the packages that I wanted to skip when debugging. Evidently, Eclipse sometimes steps through all the source code libraries, when all you want is for it to step through your code. You can bypass this by adding the packages you want to skip to the filter. According to Murach, you kinda just do it by trial and error, starting with selecting all packages and adding them. As you continue with debugging you might find you need to add more packages to the filter.
Specific steps:
1. Turn on step filtering; click the button in the toolbar on the top that looks like this: http://i57.tinypic.com/x3iccp.png
2. Go to Window-->Preferences, then in the Preferences dialog, select Java-->Debug-->Step Filtering
3. Select all packages.
4. To add additional filters, click "Add Filter", type the name of the package with a .* at the end, and click OK. Murach recommends adding these common packages to begin:
--android.*
--com.android.*
--com.google.*
--dalvik.*
--libcore.*
--org.apache.*
So to add one of these packages, click "Add Filter", type "android.*", and click OK. I ended up having all of the following packages on my Step Filter Preferences.
android., android.app., com.android., com.google., com.ibm., com.sun., dalvik., java., javax., jrockit., libcore., org.apache., org.omg., sun., sunw.*, ((and this last one is a class, not a package)) java.lang.ClassLoader
I had "Use Step Filters" checked at the top of the dialog box, and "Step through filters" checked at the bottom. Click "Apply", then "OK" to close the dialog. It should work.
Good luck!
I added appengine sdk and some other sources, and that destroyed my ADT :-(
I saw that for android-16 and android-17, the platform libraries downloaded by SDK Manager started going to ./sdk/sources whereas prior to my adding appenginge sdk, SDK Manager sent platforms to ./sdk/platforms.
It looks like the change is as a result of the appengine sdk, but for ADT, platform APIs should def be going to ./sdk/platforms
The path ./sdk/sources seems like a more generic java location and is probably the 'correct' path. Thus Android, as usual, is the problem. I was pretty sure from this point forward, I would need both ./sdk/sources and ./sdk/platforms, depending on what I was compiling.
So, I moved everything from ./sdk/sources to ./sdk/platform, deleted ./sdk/sources and then created a link 'cd sdk && ln -s platform sources'
Everything works now ;-)
For me the only solution which worked was the answer of fsbmain. Kudos to him. I can't comment on his solution because of my low reputation counter. But I want to share my knowledge ;)
I'm working on windows and don't wanted to copy the whole source tree to another location. And copy again on updates etc. So I used the possibility to insert a symbolic link which works since Windows Vista like a charm (or like Linux). For Linux you have to look at the Joe's comment under fsbmain's answer.
Assuming you have the platform in D:\sdk\platforms\android-19. Now you have to make a subdirectory sources and after that create a relative link to the real sources folder.
D:\sdk\platforms\android-19>mkdir sources
D:\sdk\platforms\android-19>cd sources
D:\sdk\platforms\android-19\sources>mklink /D android-19 ..\..\..\sources\android-19
Now restart Eclipse ... Done!