I am not sure where to properly put local properties for a project (a file path in this case) for an Android Studio project built with gradle:
local.properties: That would be what I need, however it is autogenerated and just used for the SDK-location
gradle.properties (Project level): This file is checked into version control for us to guarantee the same JVM settings for all project members for example
gradle.properties (Global): This would be possible, however I don't feel it is the correct place to put project specific settings
So either I overlooked a possibility or I must go the way of ignoring the project level gradle.properties
local.properties: You can put informations about the SDK location but also, your sensitive data like username and password of your repo access and the location of your Key to sign the Apks.
gradle.properties (Project level): It's only specified for the current project (or module) it contains dependencies, plugins, tasks, repositories for that project.
gradle.properties (Global): Can contains same data as gradle.properties (Project level) except adding dependencies. Configuration in this file are taken for all subProjects (modules in that project). this file can be located also in your gradle home directory (userDir/.gradle). If you are working with a Proxy, the best place to configure your proxy is that file.
If you want to put something specific in the local.properties then just over write once its being generated depending on the OS you have. It generates the SDK location by default but you can override like this from command line:
echo 'sdk.dir=/home/jenkins/Android/Sdk' > ./local.properties
Then you can run your gradle to build the project.
Related
How to set gradle properties for all my android projects?
I have diffrent android projetcs but whenever i change my gradel.properties file in project folder it only affect that projects.
And i cannot find the gradle.properties in .gradle folder in root directory.
How do i set common properties for all projects so i dont need to change everytime.
Gradle supports system-wide properties in a gradle.properties file in the GRADLE_USER_HOME directory, which defaults to a folder called .gradle in your home directory, e.g. C:\Users\<user>\.gradle on Windows.
These system specific properties may override project specific properties, so they can be used to specify usernames and passwords only for your local machine.
This global gradle.properties may not exist by default, but even if not, you can create one and it will be used and the properties will be available in your build script.
If your global settings require more logic than just plain properties, you can use initialization scripts, which can be placed in the same location (or the init.d subdirectory).
For MacOS users:
Open terminal and enter cd ~/.gradle
Do a ls to check whether gradle.properties already exists or not
If it doesn't exist, create one: vi gradle.properties.
If it exists, just modify the configs you want to modify and save it.
Here is the answer
This global gradle.properties may not exist by default, but even if not, you can create one and it will be used and the properties will be available in your build script.
Create one in C:\Users\user-name.gradle and name it gradle.properties without any extensions.
Documentation :
Project properties are inherited from parent to child projects.
Root Project
ext{
supportLibVersion = '25.3.1'
//supportLib
supportLib = "com.android.support:support-v4:$supportLibVersion"
}
Child Projects:
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
//supportLib
compile rootProject.ext.supportLib
}
According to Gradle documentation you can set a project property through an environment variable. All you need to do is to prepend the environment variable with ORG_GRADLE_PROJECT and Android Studio loads it as a project property for all the Android (and Gradle) projects. Example:
echo 'export ORG_GRADLE_PROJECT_foo=bar' >> ~/.zshenv
And you can access this as project property in build.gradle files:
def fooProperty = project.foo
println("Foo property is $fooProperty") // prints bar
Note: Make sure you restart Android Studio after adding the environment variable so that the property is correctly loaded.
This is my project structure. I use the Gradle Kotlin DSL. The problem is that "My app module is not Gradle-based", but it has the build.gradle.kts file.
I added also the buildSrc to the app module, but it did not help.
Project structure as:
How does your settings.gradle.kts look like?
It should contain something like this:
include("app")
This tells gradle on the root module (top level) that there is a submodule it needs to build as well.
I also see a file settings.gradle.txt in you project structure. This looks like a mistake to me, you can probably delete it?
Regarding buildSrc: The documentation states:
In a multi project build, there can only be one buildSrc directory
which must be located in the root directory
https://docs.gradle.org/current/userguide/multi_project_builds.html#sec:multi_project_and_buildsrc
I didn't find dexguard-license.txt file in dexguard.please help me in gradle setup in android studio
here is my gradle console output
Executing tasks: [:app:assembleDebug]
.....
Can't find a DexGuard license file.
You should place your license file dexguard-license.txt
1) in a location defined by the Java system property 'dexguard.license',
2) in a location defined by the OS environment variable 'DEXGUARD_LICENSE',
3) in your home directory,
4) in the class path, or
5) in the same directory as the DexGuard jar.
It's been a while since there was an updated answer, so I thought I'd update since there have been a change to DexGuard's license file setup.
I just updated from Android Studio version from 2.2.3 to 2.3 and also upgraded my Gradle version from 2.14.1 to 3.3. Upon upgrading to Gradle version 3.3, I received the same error that was documented by the OP:
Can't find a DexGuard license file.
You should place your license file dexguard-license.txt
1) in a location defined by the Java system property 'dexguard.license',
2) in a location defined by the OS environment variable 'DEXGUARD_LICENSE',
3) in your home directory,
4) in the class path, or
5) in the same directory as the DexGuard jar.
My DexGuard configuration was working just fine using Gradle version 2.14.1 with my dexguard-license.txt file in the same directory as the DexGuard jar (suggestion #5).
It turns out that the documentation for DexGuard states the following:
Note: when using Gradle 3.1+, the license file will not be found anymore when placed in the same directory as the DexGuard plugin jar.
(Source: DexGuard 7.3.10 documentation -> Quick Start -> Setting up your license file)
I wanted to keep my license file in the same directory as the DexGuard jar, so I implemented suggestion #1. I did this by adding the following line to my project's gradle.properties file:
systemProp.dexguard.license=./app/libs/Dexguard_7_3_10
Note that my DexGaurd jar and my dexguard-license.txt files are located in the following directory: {project folder}/app/libs/DexGuard_7_3_10/
I went with this solution as I not only build locally but also on a Jenkins CI. This solution prevents me from having to implement any changes on the build server itself (i.e. local environment variable, copying files to server home directory, or class path options). I hope this helps someone else that stumbles upon this problem and finds the error message confusing.
You should copy dexguard-license.txt file and dexguard.jar file to your home directory(: /user/ironman).
The licence file is available to download once you've logged in on the account > files page on https://www.guardsquare.com
See this screen shot
If you have dexguard-license.txt then you can define it under build.gradle as follows.
dexguard {
version = '9.1.+'
// Keep the license secure in your CD/CI
**license = '/../YOURDIRECTORY/dexguard-license.txt'**
configurations {
release {
..
..
}
}
I just installed Android Studio and I am just learning to build using Gradle. However, with the default project setup, my builds are located in the project directory and I would like to have them placed elsewhere (preferably outside of the project directory). Is it possible to achieve this? Where do I make a change and what change do I make?
in root build.gradle
allprojects {
buildDir = "/path/to/build/${rootProject.name}/${project.name}"
}
See also Gradle global build directory
and docs https://gradle.org/docs/current/userguide/writing_build_scripts.html
You can pass the "buildDir" property to the gradlew.bat (I'd assume you can do this in the Linux version as well but I haven't tested it)
Example:
gradlew.bat assembleRelease -PbuildDir="C:\BuildFolder"
The project iml file has a BUILD_FOLDER_PATH attribute. I haven't tried changing it myself yet, so not sure if it will work. The default value is $MODULE_DIR$/build.
Edit: I did a quick test and this did not work. Once changed, the project needs to reload because the iml file changed. Upon reload it reverts the build directory to default.
We are building our Android projects with Maven and IntelliJ IDEA. Sometimes we must execute "Reimport All Maven Projects", e.g. to update dependencies. The problem with that is that it always messes up the source folders for resources: all modules get "gen" and "target/generated-source/r" which seems to be the cause for the duplicates. So after reimporting, we need to manually delete one of those (usually the "gen" folder). Of course, we want to avoid this step. We tried several settings for the Android facet, but no luck so far.
So, how can we configure IntelliJ to do a proper Maven reimport that just works?
According to the reply of Sven Strohschein at http://youtrack.jetbrains.com/issue/IDEA-94901 you can try to:
Delete the "gen", "target" and "out" folders
Revert the changes within the "ipr" and "iml" files (or just delete them all, maybe even .idea folder)
Start IntelliJ 12
Open the pom file
Right click -> "Maven" -> "Reimport"
"Build" -> "Rebuild project"
Works fo me.
After IDEA detects and adds Android facet to module, it would start generating gen folder at usual place, but maven-android-plugin generates its own under target directory.
You need to tell IDEA to place generated files at same place where maven-android-plugin creates them.
First, use module's android facet settings and check the option to use Maven goal instead of generating by itself:
Then, go to module's settings and set output path same as Maven's, which is target directory:
Delete gen directories, Do mvn clean to clear all unnecessary files.
From your description above I guess that your project structure differs from the maven default. See Introduction to the POM. But I think the android android:generate-sources is more interesting if you have changed the assets directory etc.
Example:
<sourceDirectory>${basedir}/src</sourceDirectory>
<outputDirectory>${basedir}/target/classes</outputDirectory>