Android Studio Gradle on Server - android

I have installed Android Studio and gradle as required but while creating a new project I get this error
com.intellij.openapi.options.ConfigurationException: Failed to import new Gradle project: Could not fetch model of type 'IdeaProject' using Gradle distribution 'http://services.gradle.org/distributions/gradle-1.6-bin.zip'.
Unable to start the daemon process.
This problem might be caused by incorrect configuration of the daemon.
For example, an unrecognized jvm option is used.
Please refer to the user guide chapter on the daemon at http://gradle.org/docs/1.6/userguide/gradle_daemon.html
Please read below process output to find out more:
-----------------------
java.lang.IllegalArgumentException: URI has an authority component
at java.io.File.<init>(File.java:397)
at org.gradle.api.internal.classpath.EffectiveClassPath.findAvailableClasspathFiles(EffectiveClassPath.java:41)
at org.gradle.api.internal.classpath.EffectiveClassPath.<init>(EffectiveClassPath.java:32)
at org.gradle.api.internal.classpath.DefaultModuleRegistry.<init>(DefaultModuleRegistry.java:61)
at org.gradle.api.internal.classpath.DefaultModuleRegistry.<init>(DefaultModuleRegistry.java:55)
at org.gradle.launcher.bootstrap.ProcessBootstrap.runNoExit(ProcessBootstrap.java:41)
at org.gradle.launcher.bootstrap.ProcessBootstrap.run(ProcessBootstrap.java:32)
at org.gradle.launcher.daemon.bootstrap.GradleDaemon.main(GradleDaemon.java:22)
After lots of searching I think it is due to the fact that the .gradle folder is on a common server. "\ServerName\UserProfiles\naveen\.gradle" and AndroidStudio is not able to access it.
I also tried to change the path in Configure->Settings->gradle->ServiceDirectoryPath but it wont let me change that.
None of the problems on SO related to Android studio have any relation to what I have here.
So is there some way to change the path or maybe edit some file in AndroidStudio from which I can change Gradle Path and make it static.
I don't want to unlink my computer from server or anything like that.

go to C:\Users\user\AppData\Local\Android\android-studio\plugins\gradle\lib
and delete this files slf4j-api and slf4j-log4j12

You can use the Gradle Wrapper that doesn't relay on environment variables. If you execute gradle init on a project's root it will apply the appropriate wrapper files (along with the empty .gradle files if they don't exist).
This Android & Gradle Tutorial goes into great detail about using the platform.

I had the same problem with the gradle daemon with user home directory being a network location. Try setting a Windows environment variable GRADLE_USER_HOME to a local directory.
http://mrhaki.blogspot.com/2010/09/gradle-goodness-changing-gradle-user.html
Also, on windows 7, the user home envrionment variable might be set to a UNC path. Try adding -Duser.home=c:\some\path
Gradle Integration for Eclipse daemon startup failure

Related

Error: Could not find or load main class org.gradle.wrapper.GradleWrapperMain

My build.gradle for an Android app has become quite lengthy. Chanced upon this plugin called gradle-lint-plugin and configured it properly. In its documentation it says
Run ./gradlew fixGradleLint to automatically fix your build scripts
but upon running that I get Error: Could not find or load main class org.gradle.wrapper.GradleWrapperMain.
Does this have anything to do with the Android Studio using its own Gradle plugin? I do not have Gradle installed systemwide.
Edit: I do not wish to install Gradle systemwide - is there any way to do this within Android Studio only?
Sounds like the wrapper is not setup correctly. Likely missing the wrapper jar.
$ ls gradle/wrapper
gradle-wrapper.jar gradle-wrapper.properties
When you look in gradle/wrapper do you see gradle-wrapper.jar?
if you install gradle you can generate the jar with this command:
$ gradle wrapper
I was having this error and I solved it correcting the path which had special caracters.
Ex: .../T&G/appmobile
to ../TG/appmobile
This sometimes happens if you have "&" or "/" kind of special characters in your folder or in the parent folder. Rename those folders and the error is simply gone.

TeamCity throws FileNotFoundException trying to load android project

I setup a TeamCity server and have it successfully building several C#.NET projects. Now I'm trying to get it to build a simple Android project but cannot get it to work. Checking the BuildLog it fails with the following error:
[17:00:11][Step 1/1] Using IntelliJ IDEA External Make #141.3028
[17:00:11][Step 1/1] Loading project (2s)
[17:00:13][Step 1/1] C:\TeamCity\buildAgent\system\.jps\c67b7fe19e4788da\-1866084326\gradle\configuration.xml (The system cannot find the path specified)
[17:00:13]
[Step 1/1] java.io.FileNotFoundException: C:\TeamCity\buildAgent\system\.jps\c67b7fe19e4788da\-1866084326\gradle\configuration.xml (The system cannot find the path specified)
at java.io.FileInputStream.open0(Native Method)
at java.io.FileInputStream.open(FileInputStream.java:195)
at java.io.FileInputStream.<init>(FileInputStream.java:138)
at com.intellij.openapi.util.JDOMUtil.loadDocument(JDOMUtil.java:337)
at org.jetbrains.jps.gradle.model.impl.JpsGradleExtensionServiceImpl.getGradleProjectConfiguration(JpsGradleExtensionServiceImpl.java:125)
at org.jetbrains.jps.gradle.model.impl.JpsGradleExtensionServiceImpl.getGradleProjectConfiguration(JpsGradleExtensionServiceImpl.java:113)
at org.jetbrains.jps.gradle.model.impl.GradleResourcesTarget.computeRootDescriptors(GradleResourcesTarget.java:69)
...
The directory ..\-1866084326\ exists but it does not contain a gradle subdirectory.
I am not very familiar with the details of building gradle/android projects as I've only ever used AndroidStudio's UI to build. I have done a lot of searching but have found virtually no information about setting up an android project in TeamCity beyond what is in the TeamCity user docs that effectively says "use IntelliJ IDEA Build Runner".
I setup a build config with an IntelliJ IDEA Project build step. The project settings are parsed without error and I leave everything the way it was detected. The only parameters I have are Android_SDK = C:\Users\%env.USERNAME%\AppData\Local\Android\sdk, API_Level = 23, and system.path.macro.USER.HOME = %env.HOMEPATH%.
This is on a Windows 7 x64 Pro server.
I can build the project directly in TeamCity's workdir using AndroidStudio so I expect it is a build runner configuration issue, but I cannot find any search results for this specific error. Does anyone have any ideas?

Error in building project in Android Studio

Freshly Installed Android Studio and started new android project.
When tried to run it. Got this error from Gradle
Error:Could not open initscript class cache for initialization script 'C:\Users\Dexter\AppData\Local\Temp\asLocalRepo10.gradle' (C:\Users\Dexter\.gradle\caches\2.2.1\scripts\asLocalRepo10_d10e66d3o7exs19wwq4uj2zhv\InitScript\initscript).
java.io.FileNotFoundException: C:\Users\Dexter\.gradle\caches\2.2.1\scripts\asLocalRepo10_d10e66d3o7exs19wwq4uj2zhv\InitScript\initscript\cache.properties (The system cannot find the file specified)
I have tried to rebuild the project and also tried to delete .gradle folder but nothing worked.
I'm having the same problem and deleting just the cache.properties.lock is not enough.
The solution, as pointed before, is deleting the cache.properties.lock file, but not only in the folder pointed by Android Studio. I needed to remove every lock file inside .gradle\caches\VERSION.
So, I created a small .bat file with this:
del /s cache.properties.lock
Add this file to .gradle\caches\VERSION\ and run it. My Android Studio stopped complaining afterwards.
Hope it helps!
Error Message
Error:Could not open initscript class cache for initialization script
'C:\Users\Dexter\AppData\Local\Temp\asLocalRepo10.gradle'
(C:\Users\Dexter\.gradle\caches\2.2.1\scripts\asLocalRepo10_d10e66d3o7exs19wwq4uj2zhv
\InitScript\initscript)
java.io.FileNotFoundException: C:\Users\Dexter\.gradle\caches\2.2.1\scripts\
asLocalRepo10_d10e66d3o7exs19wwq4uj2zhv\InitScript\initscript\cache.properties
(The system cannot find the file specified)`
The most important parts of this error message are
- Could not open initscript class cache
- asLocalRepo10_d10e66d3o7exs19wwq4uj2zhv
So
Let _XXX_ = asLocalRepo10_d10e66d3o7exs19wwq4uj2zhv
Let _USER_ = Dexter
Let _GRADLE_ = 2.2.1
Solution
Delete
C:\Users\_USER_\.gradle\caches\_GRADLE_\scripts\_XXX_\InitScript\initscript\cache.properties.lock
Does this not work?
Then you have to find out the root solution. This is probably due to a corrupt IDE. Try installing another copy of Android Studio on your system.
Note: You can have multiple copies of Android Studio on your system. Here is the latest Preview. If you check the notes on the page, you can see what you need to do to install a new version on AS.
Let us know if this works...if not, we can try to elimate other possible issues
go to location
".gradle\caches\2.0\scripts\build_7l4t45nbnsvdcl79ol8u0beli4\ProjectScript"
delete cache.properties.lock file
I am also getting the same error.
So what I did is this that I cleared the Temp folder (If you don't know where it is then just hit Window+R and enter %temp% OR you can type %temp% in address bar too in File Explorer).
Now again run the project, it should run fine.
I don't know the permanent solution but what I am telling it works for me.
If anyone do know the permanent fix then please share that.
In my case, it was the roaming profile issue. Gradle Sync failed every time I switched networks from work to home. Although I was able to access the network drives by connecting with VPN, still it used to give this error. I had to move the Gradle Service Directory Path to a different location that wasn't dependent on the network.
You can do this in AS 1.4 by going to File > Settings > Build, Execution, Deployment > Build Tools > Gradle > Service Directory Path. Screen shot below:
You can also add GRADLE_USER_HOME environment variable with the same value of the location for making it a default for every project (http://blog.james-carr.org/2011/05/04/setting-gradle-cache-to-a-common-location/). You may refer to the following page for more info on moving Android related stuff to different locations: http://www.littlecpu.com/android-studio-c-drive
File -> Invalidate Cache / Restart worked for me.
In my case I have deleted .gradle folder and clean the project on re run the project was working fine.
I had similar issues. For me the solution was simply to delete all files inside the folder C:\Users\Dexter.gradle\caches\2.2.1\scripts\ Also i removed VCS configuration from android studio. No need to install new Android Studio to fix the issue.
I have same problem. just restart your Gradle and then clean your project. i hope this help
For Me Issue get resolved by giving permission
For window
C:\Users
Right click on Users >> Click on Security Tab >> Add Group and username there
as for example SYSTEm, your comany mail id
For Linux
provide 777 permission for .android and .gradle folder by using
sudo chmod 777 -R .android/
sudo chmod 777 -R .gradle/

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.

AOSP and IntelliJ IDEA

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.

Categories

Resources