Android gradle project directory variable - android

I am trying to write a script in gradle that requires opening up a file. I am trying to find the current directory where the project is installed. so I can open a file in my "raw" directory.
Note: I am aware that I can use a temporary file to find the current location of the application. However, I am trying to stay away from that solution.
I am trying to find out if gradle has a buildDir variable that I can use in my task instead.

See the Gradle docs. Specifically, you're interested in projectDir (The directory containing the build script) or buildDir (projectDir/build).

Related

How to change Flutter Module's Directory

When I created a flutter module through the command "flutter create -t module..." and I forgot to use "cd.." to change the directory of the root folder, for me it is "C:\Projects" and it created the module inside my Android Project Directory, which is "C:\Projects\MyAndroidApp", How do I change the directory? and is it okay to have the flutter module inside 'MyAndroidApp' ?
You can simply move the project folder of the module to the intended location. This shouldn't cause much issues unless you're referencing the module on a Flutter project, which you might just need to update its path.

Some light on gradle.properties, settings.gradle, gradle-wrapper.properties and local.properties

I use them often when configuring my project but mostly add snippers as instructed. I have absolutely no clue which file is for what exactly. Can anyone give a clear picture what each file is for.
So far I think
local.properties for environment paths like sdk/ndk location
settings.gradle for including all modules in project where each module has it's own build.gradle
gradle.properties ?
gradle-wrapper.properties ?
gradle.properties
Using gradle.properties to create universal variables
This solution is limited to Android projects as far as I know. In /gradle.properties you can define your universal or project level variables as such: Link
myBuildToolsVersion=20.0.0
myMinSdkVersion=10
myTargetSdkVersion=22
myCompileSdkVersion=22
gradle-wrapper.properties
Internally, Android Studio uses the version of Gradle that is defined in the wrapper configuration. That configuration can be found in gradle/wrapper/gradle-wrapper.properties. When Google decides that it is time to use a new version of Gradle, Android Studio will display a message nudging you to upgrade. All you need to do then is click the message and Android Studio will edit the properties file and synchronize the Gradle installation for you. Link
local.properties
The local.properties file goes in the project's root level.
This file should not be included in source control. After (incorrectly) including this in source control, then deleting the file locally, Android Studio re-created the file for me automatically.
Here is the example content of this file:
## 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.
#Thu Aug 14 14:49:26 PDT 2014
sdk.dir=C\:\\Program Files (x86)\\Android\\android-studio\\sdk
Note the sdk.dir= reference to the location of the Android Studio SDK installation (which may be different on different machines).
Link
settings.gradle
':lib' is a logical project path, which gets mapped to a physical path based on information provided in settings.gradle.
A multi-project build can have an arbitrary directory structure, which is configured in settings.gradle. No need to move directories around, unless you want to. Link
For more and more info about gradle you need to check below links which help you more know about gradle and gradle system. Gradle makes developer life easy for not taking to much headache about library updation , apk generation , import lib easily , product flavors and many more.
http://www.vogella.com/tutorials/Gradle/article.html
https://developer.android.com/studio/build/gradle-tips.html
Gradle includes two properties files, located in your root project directory, that you can use to specify settings for the Gradle build toolkit itself:
gradle.properties
This is where you can configure project-wide Gradle settings, such as the Gradle daemon's maximum heap size.
local.properties
Configures local environment properties for the build system, such as the path to the SDK installation. Because the content of this file is automatically generated by Android Studio and is specific to the local developer environment, you should not modify this file manually or check it into your version control system.

Difficulties setting up Gradle to send ProGuard mapping files to Firebase

I am trying to follow this documentation tutorial by Firebase to setup Android Studio to automatically send my ProGuard mappings file when building a release APK for my Android application.
However, I couldn't seem to understand steps 4 and 5 in the "Uploading ProGuard mapping files with Gradle" part, mainly because I didn't find any gradle.properties file in my project root or home path and because I wish to automate the execution of the app:firebaseUploadReleaseProguardMapping task in Android Studio, which I don't know how to do.
This is the contents of the gradle.properties file I've created in my project root directory:
FirebaseServiceAccountFilePath = /app/firebase-crash-reporting.json
The firebase-crash-reporting.json file is my Firebase crash reporting private key. My mappings file is generated in the /app/build/outputs/mapping/release/ directory, if that helps.
Please assist me in completing those 2 steps and automatizing the process in Android Studio.
Just add
afterEvaluate {
assembleRelease.doLast {
firebaseUploadReleaseProguardMapping.execute()
}
}
In the android section of build.gradle file.
This will automatically upload the ProGuard mappings file to Firebase as well as run/deploy the APK to the device using ADB.
gradle.properties is owned and managed completely by you. You have to create it if it doesn't already exist. This means you should probably read the Gradle documentation on it to best understand how it provides properties to your builds, and which location is best for your properties.
You are not even obliged to use gradle.properties. You can also specify all the properties for the Crash Reporting plugin via the command line.
When you specify a path for the service account file, you should specify the full, unambiguous path to the file. In your example, it looks like you're assuming that it will look under the app directory in your project. If you want to do that, you still have to give the full path to the file.

Moving a Cocos2d-x Android project around in the local file system

I've used create-android-project.sh to successfully create an Android app as part of my Cocos2d-x project. Now I want to move the app's directory and all contents to a different location in my local file system.
When I try to build the app after moving it I receive the error:
'make: *** Android NDK: Aborting. Stop.'
How can move my current project around the local file system and still have it build and run correctly?
If I need to re-create the Android project after modifying the creation scripts that's fine too. I looked through create-android-project.sh and it wasn't obvious to me how I can modify the script to create the project in another directory of my choice. Or perhaps I need to adjust some of the settings in Eclipse.
Changing the COCOS2DX_ROOT in build_native.sh to an absolute path makes the project compile successfully.
This is similar to NDK_ROOT defined at the top of the file.

Ant build Android project with dependency lib

I have two Android projects, one shared library and the app. Now I want to compile the app with dependency to the library. In Eclipse, it works very well. After that, I upload it via git to my repository and trigger Jenkins to build both projects.
My problem is, that the error occurs: "sdk/android-sdk-linux/tools/ant/build.xml:440: ../shared-lib resolve to a path with no project.properties file for project". That's clear, because in Jenkins the jobs are stored different than under Eclipse.
Another problem is, that Eclipse compiled the shared to ".jar" and Ant compiled it to "classes.jar" (is named in sdk/android-sdk-linux/tools/ant/build.xml).
Ant scripts should allow you to include whatever files you need. In your case I will suggest you move the reference to the shared-lib to local.properties file (this file should also be read by the ant script generated by update-project. Keep the adequate path for jenkins in the repository and modify the file locally for the local built. In the file in the repository you will need to have something like:
android.library.reference.1=../classes.jar
EDIT By the way the suggestion of the second properties file is just because this file is really meant to store location-specific properties.
I fixed it with copy files. The first project builds my shared-lib.jar. The other projects (phone and tablet) copy this file (shared-lib.jar) to there libs-folder and build correctly. But now I have different projects.propertieson the server and my dev-client. This one is not checked in into git.

Categories

Resources