AOSP and IntelliJ IDEA - android

Has anyone tried to work with AOSP using IntelliJ IDEA? I see in Android sources a specific folder (development/ide/intellij) but I cannot find any information how to use it in case of Android development (for Eclipse the information can be found here: http://source.android.com/source/using-eclipse.html) Can anyone provide similar instructions how to start developing Android in IDEA?

Also a good reading here: https://shuhaowu.com/blog/setting_up_intellij_with_aosp_development.html
If you get
Couldn't find idegen.jar. Please run make first.
You'll need to generate it first:
source build/envsetup.sh
cd development/tools/idegen
mm
croot
development/tools/idegen/idegen.sh
Be prepared that AOSP files indexing in IJ takes long time (more than 1 hour on my notebook with an SSD on board), a reason to use Eclipse, as I believe it doesn't need to build indexes so loads AOSP code much faster.
It's worth reducing android.iml file with removing AOSP parts you are not interested in. You can add them to development/tools/idegen/excluded-paths via a regular expression pattern, see README file there.
I added following lines to excluded-paths:
^cts
^developers
^development
^external
.*/tests/.*
^sdk
so my android.iml got quite moderate size and loads in about 1-2 minutes instead.
idegen has also intellij-gen.sh which can generate IJ project for given module.
As mentioned in the article above, you can tweak IJ to work faster (add more RAM, etc). Here goes my idea64.vmoptions just in case:
-server
-Xms2048m
-Xmx4096m
-XX:MaxPermSize=1024M
-XX:ReservedCodeCacheSize=1024M
-XX:+UseCodeCacheFlushing
-XX:+UseCompressedOops
-XX:+UseConcMarkSweepGC
-XX:+UseParNewGC
-XX:ParallelGCThreads=8
-XX:+AggressiveOpts
-XX:+CMSClassUnloadingEnabled
-XX:+CMSIncrementalMode
-XX:+CMSIncrementalPacing
-XX:CMSIncrementalDutyCycleMin=0
-XX:-TraceClassUnloading
-XX:+TieredCompilation
-Dsun.io.useCanonCaches=false
-Djava.net.preferIPv4Stack=true
-Djsse.enableSNIExtension=false
You can google idea.vmoptions optimization, there are some posts about it (and where I took my IJ config from)

From AOSP root folder,
1) First build your target. That will generate whatever java files that need to be generated during aosp build.
2) Create a shadow dir of aosp dir using lndir.
Assuming your aosp dir is ~john/work/aosp/ics.
Then create ~/john/work/aosp/icsshadow
Cd to icsshadow and invoke "lndir ../ics". That will create symlinks to everything under ics.
3) Now you use icsshadow for all the stuff your IDE needs/generates. If you use ics folder, the aosp build some times fails if the IDE generates any build artifacts.
4) cd to icsshadow directory.
Invoke development/tools/idegen/idegen.sh
Wait until it is done.
5) If you want to use IntelliJ, open android.ipr from icsshadow folder. If you want to use Eclipse, Please check Using Eclipse to edit/browse AOSP code.

Official instructions can be found by going to development/tools/idegen path and checking the README file. It's a good idea to read it yourself. This is the content for IntelliJ:
If you're using IntelliJ...
If this is your first time using IDEGen...
IDEA needs a lot of memory. Add "-Xms748m -Xmx748m" to your VM options
in "IDEA_HOME/bin/idea.vmoptions" on Linux or
"IntelliJ IDEA.app/Contents/Info.plist" on OS X.
Create a JDK configuration named "1.6 (No Libraries)" by adding a new
JDK like you normally would and then removing all of the jar entries
under the "Classpath" tab. This will ensure that you only get access to
Android's core libraries and not those from your desktop VM.
From the project's root directory...
Repeat these steps after each sync...
1) make (to produce generated .java source)
2) development/tools/idegen/idegen.sh
3) Open android.ipr in IntelliJ. If you already have the project open,
hit the sync button in IntelliJ, and it will automatically detect the
updated configuration.
If you get unexpected compilation errors from IntelliJ, try running
"Build -> Rebuild Project". Sometimes IntelliJ gets confused after the
project changes significantly.
The following error message might pop up when following the instructions.
Couldn't find idegen.jar. Please run make first.
You can fix the error message by reading here: https://www.protechtraining.com/blog/post/860?ncr=1

Run the below command from the Android source root directory.
make idegen -j4 && development/tools/idegen/idegen.sh
Then launch IntelliJ idea, and select the .ipr file generated. Then on the next screen select the .ipr based project property.
Works for me and better than using the android studio, because there is an annoying background scan all the time with the android studio.

Related

How to make gradle faster

I installed the android sdk and gradle on Windows 8.1.
It is too slow because the build tool takes too much time.
Can I get rid of gradle?
How else can I make it faster?
There are some thing, which could help a bit:
1) In Settings->Build->Compiler and add Command line options:
--offline --parallel
and VM options:
-Xmx2048m -XX:MaxPermSize=512m- -
2) In the file gradle.properties add line org.gradle.daemon=true
3) Give a try to Genymotion emulator.
4) Move project to SSD disk. Or flash disk - build time can drop to half.
Last option is not to use AS and Gradle at all. Switch to Eclipse (make new project, move res and src files + import all libraries you using, for example NDK is easier to set up there), but it's also not that "heavy" and up to date as AS, so probably not much helpful after all.

CreateProcess error=206, The filename, or extension is too long

CreateProcess error=206, The filename or extension is too long - Android Studio
What does this error mean and how can I solve it?
I tried Android-Studio in committing projects and Tortoise SVN, seems like tortoise-svn does the job unlike android-studio's plugin which is SVN. I dont really understand why, but Tortoise-svn is working so I think this could be an answer.
Make long story short: The temporary-fix is using Tortoise Svn rather than using Android-Studio's SVN.
Windows has a max path length of 260 characters. See max path length of 260 characters. See Android Studio - Unable to open PNG file
According to another thread the "svn cmd absolute path" works, but the relative one "cd /your/project/path;svn cmd yourproject" doesn´t (It´s a Windows File System "Problem")
Android Studio seem to work with relative paths, Tortoise with absolute. The error message also says
cannot run program ( IN directory .../.../yourproject)
Which confirms this assumption.
Hopefully they will change it in future!!
I had the same problem and installing Tortoise SVN didn't solve it. I proceeded to commit individual directories in my project step by step, trying to find the file/directory that was causing the problem. My surprise was when I finished all commits and no error had arised.
So the solution for my problem was to commit all my files/directories step by step.
I know the thread is a bit old but here is a a work around for googlers ,
Android Studio gives you the exact address of the folder which can not be committed:
Error:Cannot run program "svn" (in directory "c:\blah-blah"): CreateProcess error=206, The filename or extension is too long
Unless AS or Microsoft does something for supporting file names longer than the current limitation, here is a couple of workarounds to pass this :
1- to commit the given folder c:\blah-blah using another svn client eg. TortoiseSVN
2- to move your project folder closer to the root of the drive, for example if your project is in d:\Development\Android Studio\sources\project x\Version 3\... try to move it closer to the root, by removing and/or renaming in between folders like: d:\dev\as\src\x\v3\... or d:\x\v3\...
3- I read somewhere that creating a virtual drive in windows from the last folder would work too, for example, create a z:\ and assign it to d:\Development\Android Studio\sources\project x\Version 3\ but I read somewhere else that this might not work cause the AS svn client work with absolute path of files, any way I made the job done with options 1 and 2 and never got to try the third option
The error is often produced when too many files are commited at once and the command line client is used; as the files are delivered to the client in one line, the line becomes too long (svn commit file1 file2 ...). See also SVN commit fails when committing lots of files in one commit (resulting svn command length exceed the limit). My solution to this problem was to uncheck "Use command line client" in the settings under "Version Control - Subversion".

Titanium Appcelerator Android module : How to create a proxy?

This is not a question but is an answer to the issues I was stuck up while creating custom Android module for Titanium appcelerator.
I was able to run the ExampleProxy provided by the framework but was having problems creating my own Proxy class.
I was able to access the proxy. After lot of search I got the reference of following question -
http://developer.appcelerator.com/question/153993/how-to-create-a-proxy#answer-264746
Following response partially works-
"Thank you very much Benjamin Bahrenburg for the clarification. Also i
thank Mads for your quick response.
Exact answer i was looking for : Need to remove the files in the bin,
libs, and build folder. Then do a clean, in Eclipse. After all of that
it tends to build. Please make sure you are using Ti 3.1.0 ( not 3.1.1
which has an issue)."
In addition on windows 7 machine I had following observations-
The Module-generated folder in C:\Users\username\AppData\Local\Temp\ must be deleted.
In the module folder delete following contents - entire contents of bin and libs and delete everything in build except \build\generated\Application.mk
It cost my 1 day to solve this problem.
to successfully create and run a ViewProxy, you have to:
change its file/class name (from ExampleProxy) to ViewProxy
clean the dirty files, including: build/, dist/, and some "lib.so " files in libs/ folder.
execute ti clean in your "Titanium app" folder.
your ViewProxy is not the same as the module name. e.g. your module name is: "GaodeMapModule", your proxy name should not be: "GaodeMapProxy", it doesn't work.

"Conversion to Dalvik format failed with error 1" -- on export only

I know this is a repeat question but I've read and tried every solution on this site and I'm still getting the error; also, I'm getting it ONLY when I export my signed apk from Eclipse. I'm able to build and run the unsigned apk.
I have:
Deleted (and later restored) all libraries from the build path
Cleaned and rebuilt all my projects
Restarted Eclipse with -clean option
Re-create the app project from scratch
I know error 1 means I have duplicate symbols but I've checked, clean and rebuilt my build path a million times and I still get the error, only when I export.
If I had duplicate symbols, wouldn't I get an error 1 for my unsigned apk too?
If I really do have duplicate symbols, how can I get Eclipse to tell me what they are? All I get from the export wizard is a one-line error dialog. :(
I don't get any errors when I manually sign the apk, but when I install it on a phone I get a simple error: "Application not installed." :(:(
My project structure is as follows:
One Android library project with 99% of my code. It has one copy of the required jar files in the build path.
One Android app project with two classes. It references the library project via the Android tab, NOT the Java build path. There are no additional sources, projects or libraries referenced in the build path except for Android 2.1. I even re-created this project from scratch (I didn't re-created the library project because it's much bigger).
Everything was working a few days ago! Any suggestions are much appreciated!
Thanks in advance...
EDIT-UPDATE: The error goes away when I disable Proguard. Very strange.
This is an issue with Proguard in the Windows developer tools - edit Android SDK\tools\proguard\bin\Proguard.bat
Replace:
call %java_exe% -jar "%PROGUARD_HOME%"\lib\proguard.jar %*
with:
call %java_exe% -jar "%PROGUARD_HOME%"\lib\proguard.jar %1 %2 %3 %4 %5 %6 %7 %8 %9
Keep a reference to this solution because next time you update the SDK tools it'll probably be reintroduced (has been present in last few releases).
Upgrade your Proguard to its latest version i.e., 4.7...
Dowload the zip from http://sourceforge.net/projects/proguard/files/latest/download?source=files .... then copy the "lib" and "bin" folders from the zip to your sdk/tools/proguard/ to replace the default or say old "bin" and "lib" .... try exporting your project once again...
Go to project and unselect Build Automatically. Then Clean the project and Build all. Worked for me to export signed application package
This was driving me insane too. I tried everything, changed all my external libraries and so on but nothing worked. I tried a newer version of proguard without success.
Turns out I was using a library called "GridLayout" to support older devices. After I renamed the class "GridLayout" to "CustomGridLayout" it worked fine. Seems like you can't have duplicate class names.
Here was the key that worked for me
http://android.foxykeep.com/dev/fix-the-conversion-to-dalvik-format-failed-with-error-1-with-adt-14
Supposedly fixed in ADT-15, the workaround is
1) For each X_src element,right click on it and then Build Path > Remove from build path.
2) A popup will open. Make sure that “Also unlink the folder from the project” is checked and then accept it.
You can still debug into library code but you need to manage your breakpoints in those projects and then step through the code in the class file tabs.
I tried a few of the above solutions, and had no luck. Then, I closed Eclipse, and re-opened it, and was able to export successfully. If I try again however, it wouldn't work.
So, I think maybe I only get one successful export per "open" of Eclipse. Not an ideal solution by any means, but when all else fails give it a shot. It worked for me.
The accepted answer to this question (from 2011) did not work for me. However, the correct answer to this question is posted here:
Android export give a "Conversion to Dalvik format failed error1"
Unselect Build Automatically works for me. Tanks anjaneya;
0)Unselect Build Automatically
1) Clean the project
2) Build project.
3) Export Signed Application in Android Tools options.

How to rebuild android source code after making changes in android source files

I have android source code in my system and it works fine. But when i make some changes in android source files and run "make" it doesn't generate/update any files
Please correct me if i am wrong,
i) system should generate a new system.img file if changes have been made to its source code
ii) android kernel file-zImage file doesn't change with any change even if we make any changes to the source code
Another question if i create a new library folder inside /libcore it gets automatically picked up when compiling. For creating a new library folder outside /libcore i added its path in /build/core/main.mk and .classpath file. Still its not getting picked up during compilation. Can someone please confirm where all we have to make changes for adding a new library file outside /libcore
Regards,
Yogesh
This depends on exact repository that you have checked out. But for majority of them the following recipe will work:
http://source.android.com/source/download.html
Note, if you are using the most recent build you must have 64-bit system
UPDATE: For some reason the page above is missing some vital steps. So here they are
After you done 'repo sync' step ( takes a while, but I assume that you did since you have the source files ), do the following:
$ . build/envsetup.sh
$ lunch
The last command will give you a list of options for which platform you want to build. If you want to build for the emulator choose full-eng. Otherwise choose one for your specific device vendor.
After choosing the platform make sure you do full make of everything first, because the entire android platform is very interdependent. So you need to make sure you have all the components.
When developing you can build individual components pretty fast. By using the following command:
mmm <component_directory_name>
For example:
mmm external/rsync
Also, the build system does not change put the output and intermediate files with the source code. Everything goes into out/target directory.
It depends on the change you want to make.
In an easy case, if the change is local (e.g., adding some new lines into an existing android source files called xxx.c), you can easily run:
mm -B (under the root directory of xxx.c)
adb remount
adb sync
adb reboot
In other cases, say, you create a new system service to replace the old one which is started at boot-up time as shown in init.rc file. Then, you probably need to:
Update init.rc file
Build whole android source
Flash new image

Categories

Resources