When building a regular Android app with Gradle, I can add params as such:
./gradlew assembleRelease -Pusername=foo -Ppassword=bar
With Flutter, this is what I'm supposed to call in order to assemble an APK:
flutter build apk
How do I pass the params to Gradle in this case?
P.S. I'm trying to use Jenkins credentials in a pipeline configuration. I do not want to expose my password, so avoiding using the arguments and putting it directly into the project is not an option.
You can pass variables via the environment, I use this method with Jenkins. The job can be configured to pass the credentials via environment variables.
In your build.gradle (where needed):
username = System.getenv('SECRET_USERNAME')
password = System.getenv('SECRET_PASSWORD')
Please notice that System.getenv(...) returns null if the variable is not defined.
In your development environment you should export the variables:
$ export SECRET_USERNAME="my secret username"
$ export SECRET_PASSWORD="my super secret password"
Please, I do not know which IDE are you using, but both IntelliJ and AndroidStudio do support declaring environment variables.
You can set project properties through environment variables like ORG_GRADLE_PROJECT_foo=bar, so that you don't have to modify the gradle scripts, for example:
export ORG_GRADLE_PROJECT_username=foo
export ORG_GRADLE_PROJECT_password=bar
flutter build apk
Docs: Project properties
Related
If i set environment for android sdk it is not seen by gradle script , unless i use
the command as this e.g: ANDROID_SDK_ROOT:path to sdk ./gradlew clean otherwise it throw error : cannot find ANDROID_SDK_ROOT
I try to define environment variable locally and globally and make it presistant but cannot see also by gradle
I am trying to install the mqtt module to android_armv7. To do this, I create a folder named build and run this: ~/Qt/5.12.4/android_armv7/bin/qmake qmake -r ... Unfortunately I recieve this error:
Project ERROR: You need to set the ANDROID_NDK_ROOT environment variable to point to your Android NDK.
Could not read qmake configuration file /home/stefan/Qt/5.12.4/android_armv7/mkspecs/android-clang/qmake.conf.
Error processing project file: ../qtmqtt.pro
I have tried going to tools->External->Configure->Environment->External Tools->Update Translations and wrote:
"ANDROID_NDK_ROOT=/home/stefan/Downloads/android-ndk-r19c/android-ndk-r19c
PATH="
in the Environment Change section. It didn't work. A strange thing (for me) is that I can deploy an application (without mqtt) on android_armv7. I am using Linux. What should I do now?
My Gradle build looks at an environment variable called BUILD_NUMBER to determine the version to allocate to my android application as follows:
def buildNumber = System.getenv("BUILD_NUMBER") ?: "local"
So as long as that environment variable is set, the build number is used in defaultConfig as follows:
versionName "1.4.0."+buildNumber
Usually, Jenkins will call this Gradle build and supply the BUILD_NUMBER environment variable.
If I run the Gradle build from my command prompt, I know I can set BUILD_NUMBER = x.
However, if I build using Android Studio, how can I set the BUILD_NUMBER environment variable through Android Studio itself?
One option is to make use of gradle properties that can be overriden by environment variables. You can read about it here.
If the environment variable name looks like ORG_GRADLE_PROJECT_prop=somevalue, then Gradle will set a prop property on your project object, with the value of somevalue.
What this means is that you can
set BUILD_NUMBER=42 in your .properties file (project, or global) as you would usually do,
and in your CI you would name the environment variable ORG_GRADLE_PROJECT_BUILD_NUMBER, overwriting or setting BUILD_NUMBER in your CI build.
Note: Use gradle.properties in your project root directory, and do not modify local.properties.
I ended up using the following in my build.gradle:
def buildNumber = System.getenv("BUILD_NUMBER")
if (buildNumber == null) {
Properties properties = new Properties()
properties.load(project.rootProject.file('local.properties').newDataInputStream())
buildNumber = properties.getProperty('buildNumber')?:"NoBuildNumberFound"
}
Because the local.properties file is not supposed to be committed to your source code repository, each developer manages their own copy.
So if they want to set the buildNumber on their local Android Studio, they simply add the following to their local.properties:
buildNumber=7
So on a local developers machine, the build number will be set to what ever they put into their local.properties file, but on our Jenkins server, it will use the environment variable BUILD_NUMBER
Our Jenkins server sets the BUILD_NUMBER environment variable
These are just environment variables.
If under Windows, go to the OS control panel and type "environment" in the search box at the top right. Then click on "Edit environment variables for your account", highly user friendly and no admin rights required. Restart the Android Studio after the edit.
If under Linux, edit .bashrc in your home folder (vi ~/.bashrc or with some other editor). Environment variables can be set there. source ~/.bashrc (or logout/login) and restart the Android Studio after the edit.
I want to use Indic-Keyboard github project for build an application. So when I clone it to my repository and try to build I get build failed with an exception that
Cannot evaluate module ime : Configuration with name 'default' not found.
I create my own release key for key store in android studio 1.1.0 according to developer.android.com's suggestion for Signing Your Own App
and store it in E:\GitHubCloneProject\AddSubmoduleAndroidStudio\CloneProject\java\keystores\android.jks.
and also set ANDROID_HOME=E:\Android Sdk in my system environment variable by using the
following suggestion from stackoverflow.
I follow the procedure for initialize,update and add submodule according to github project "austimkelly/my-android-project/How-to-Use".
When I try to import in my android studio I get the error
Can not invoke method readLine() on null Object.
I'm using gradle 2.2.1.
checkout your indic-keyboard/ime folder, if it is empty follow these steps-
after using this command "git clone --recursive git#github.com:smc/Indic-Keyboard.git" use cd indic-keyboard to navigate to project directory
use "git checkout -f HEAD" to check the status
use "git submodule update --init --recursive" or "git submodule foreach --recursive git checkout master" as suggested in this stackoverflow question.
then go to build.gradle in your clonned directory/indic-keyboard/java and remove signingConfigs and buildTypes part from it, after saving import java folder to android studio and hopefully everything will work
#CSE09 are you able to use it in your app, if so please guide me how you did that, as I am struggling to convert it into a library project in android studio
I am trying to setup cocos2dx with eclipse on a MacOs Lion. I am following the tutorial below:
http://www.raywenderlich.com/11283/cocos2d-x-for-ios-and-android-getting-started
When I try and execute the ndk build shell tool i get the following error:
Davids-iMac:~ davidcavanagh$ /Users/davidcavanagh/Downloads/android-ndk-r8b/ndk-build ;
exit;
Android NDK: Could not find application project directory !
Android NDK: Please define the NDK_PROJECT_PATH variable to point to it.
/Users/davidcavanagh/Downloads/android-ndk-r8b/build/core/build-local.mk:130: *** Android
NDK: Aborting . Stop.
logout
[Process completed]
I have tried defining the NDK_PROJECT_PATH through the terminal by using
export NDK_PROJECT_PATH=/Users/davidcavanagh/Downloads/android-ndk-r8b/
This doesn't work. Can anyone help me as I have been stuck on this for ages. Is there a certain way of setting the path that I am not doing?
Thanks
Re-read and re-read again his tutorial. You shouldn't be executing the ndk-build script without supplying the arguments it needs for building your project.
He mentions using the create-android-project.sh script inside the cocos2d-x directory. Make sure you do that, and follow the steps there where you'll supply the project name, reverse-domain application ID (e.g. com.company.project), and so on. This will generate your project directory inside of the cocos2d-x directory, which you can easily & safely move to another location.
Once you have that project set up, you can import it into Eclipse, which, primarily, allows you to build the Android project, but does not refer to the C++ code directly. (You'd need to get CDT and the NDK plugin to actually hook your C++ code up inside of Eclipse).
Otherwise, what's worked for me so far is to run the build_native.sh script inside the project directory whenever I have new code that I want to test on my device. This script references the jni/Android.mk file, where you need to specify your header paths and *.cpp files (similar to how you'd have to specify all of your implementation files with g++ on the command line).
But before you do that, you need to make sure all the environment variables that build_native.sh uses are set up. You can either put them in your ~/.bashrc file, or you can just stick them in that project directory (up to you. bashrc will make them available to all projects whenever you launch a new terminal, whereas hardcoding them into build_native.sh will only offer them to that specific project). I think all you need is to assign the full paths to NDK_ROOT, COCOS2DX_ROOT, and APP_ROOT, and build_native.sh should run successfully.
If you look down at the bottom of build_native.sh, you'll notice an invocation of ndk-build, along with all the necessary parameters that you were missing in your terminal session.