Importing project library from github giving unexpected behaviour - android

I am using first time git hub library in my project and new to android.I am trying to make project in which i need to use graph for this I am using ease graph project from git hub but it is giving me an error
Error:(9, 0) Could not find property 'file' on SigningConfig_Decorated{name=release, storeFile=null, storePassword=null, keyAlias=null, keyPassword=null, storeType=null}.
this is the file coding available
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
signingConfigs {
release {
storeFile file(STORE_FILE)
storePassword STORE_PASSWORD
keyAlias KEY_ALIAS
keyPassword KEY_PASSWORD
}
}
defaultConfig {
applicationId "org.eazegraph.app"
minSdkVersion 9
targetSdkVersion 21
versionCode 1
versionName "1.0"
}
lintOptions {
abortOnError false
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.release
// this is used to alter output directory and file name. If you don't need it
// you can safely comment it out.
applicationVariants.all { variant ->
variant.outputs.each { output ->
def file = output.outputFile
String parent = file.parent
if (project.hasProperty('OUTPUT_DIR') && new File((String) OUTPUT_DIR).exists())
parent = OUTPUT_DIR
output.outputFile = new File(
parent,
(String) file.name.replace(
".apk",
// alter this string to change output file name
"-" + defaultConfig.versionName + "-build" + defaultConfig.versionCode + ".apk"
)
)
}
}
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile project(':EazeGraphLibrary')
compile 'com.android.support:appcompat-v7:21.0.3'
}
any help please..

It seems you have not defined the variables STORE_FILE, STORE_PASSWORD, KEY_ALIAS, KEY_PASSWORD in your script. You can do it as follows :
apply plugin: 'com.android.application'
def STORE_FILE= "File location goes here"
def STORE_PASSWORD= "Store password"
def KEY_ALIAS= "Alias to use"
def KEY_PASSWORD= "password to the alias"
android {
....
}

Related

Setting up development and production environment for android application in Android Studio

I have 2 questions regarding this issue.
if in laravel/web we have .env file to set environment to "development" or production and automatically connect to different database. how about in android/kotlin/android studio?
and how to make my application request to my localhost (127.0.2.1) on PC if it's in "development" environment and request to real url API if it's in "production" environment. FYI, I dont use emulator. I use my phone to test my application.
Yes this is possible in your Android application as well. You just have to modify your build.gradle file to manage your BuildConfig based on your dev, test or production environment.
Here's a sample build.gradle file from one of my project.
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
def keystorePropertiesFile = rootProject.file("../Path_To_KeyStore/keystore.properties")
def keystoreProperties = new Properties()
keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
def appPropertiesFile = rootProject.file("app-settings.properties")
def appProperties = new Properties()
appProperties.load(new FileInputStream(appPropertiesFile))
android {
compileSdkVersion 27
buildToolsVersion "27.0.3"
signingConfigs {
MyAppSigningConfig {
keyAlias keystoreProperties['keyAlias']
keyPassword keystoreProperties['keyPassword']
storeFile file(keystoreProperties['storeFile'])
storePassword keystoreProperties['storePassword']
}
}
defaultConfig {
applicationId "com.example.myapp"
minSdkVersion 21
targetSdkVersion 27
versionCode appProperties['app.version.code'] as int
versionName appProperties['app.version.name']
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
def buildVariant = getBuildVariant()
def environmentPath
if ((buildVariant == "Release")) {
environmentPath = appProperties["env.path.live"]
} else if ((buildVariant == "Debug")) {
environmentPath = appProperties["env.path.test"]
} else {
environmentPath = appProperties["env.path.live"]
}
def envPropertiesFile = rootProject.file(environmentPath)
def envProperties = new Properties()
envProperties.load(new FileInputStream(envPropertiesFile))
println("buildVariant = $buildVariant")
for (String key : envProperties.keySet()) {
buildConfigField "String", key.replaceAll("\\.", "_").toUpperCase(), envProperties[key]
}
}
buildTypes {
debug {
applicationIdSuffix ".debug"
manifestPlaceholders = [appName: "#string/app_name_debug_test"]
}
release {
manifestPlaceholders = [appName: "#string/app_name"]
signingConfig signingConfigs.MyAppSigningConfig
minifyEnabled false
multiDexEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
def getBuildVariant() {
for (TaskExecutionRequest t : gradle.getStartParameter().getTaskRequests()) {
for (String command : t.args) {
if (command.matches(":app:generate(.*)Sources")) {
return command.replaceAll(":app:generate(.*)Sources", "\$1")
} else if (command.matches(":app:assemble(.*)")) {
return command.replaceAll(":app:assemble(.*)", "\$1")
}
}
}
return "Release"
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
implementation 'com.android.support:appcompat-v7:27.1.0'
implementation 'com.android.support:recyclerview-v7:27.1.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
}
I have two different build variants here. One is for release and the other is for debug. And I have three properties file in the application directory. These are as follows.
The app-settings.properties file looks like this.
app.version.code=1
app.version.name=0.0.1
env.path.live=live-env.properties
env.path.test=test-env.properties
The test-env.properties looks like
base.url.auth="http://localhost:8888/auth/"
base.url.communication="http://localhost:8000/communication/"
base.url.site="http://localhost:8000/"
api.key.auth="demo_key"
And the live-env.properties is like
base.url.auth="http://auth.yourapp.com/auth/"
base.url.communication="http://yourapp.com/communication/"
base.url.site="http://yourapp.com/"
api.key.auth="live_key1223ssHHddSSYYY"
So once the build.gradle and the application properties are setup, you need to sync with gradle to generate the BuildConfig.java file. You will see the file is generated automatically with the values found from your properties file.
From anywhere in your code, you might access the environment variables like the following.
const val BASE_URL = BuildConfig.BASE_URL_SITE
const val BASE_URL_AUTH = BuildConfig.BASE_URL_AUTH
Get the desired application build from the left side menu of build variants in Android Studio.
One of my colleague named Sajid Shahriar helped me to understand the setup for different build variants. Hence, I am sharing this with you. Hope that helps.
Add inside inside app level build.gradle file
android {
flavorDimensions "full"
productFlavors {
production {
versionCode 17
versionName "1.1.0"
dimension "full"
}
develop {
applicationId "dev.kadepay.app"
versionCode 17
versionName "1.1.0"
dimension "full"
}
}
if set up different package name
Add this line
applicationId "dev.kadepay.app"
and after sync build check build variants

How to include additional configuration file inside build.gradle file

Is there any ability to include file inside build.gradle file?
I want to separate same configurations from few projects into one file and than just include it inside build.gradle.
For example, now I have file like this:
apply plugin: 'com.android.application'
apply plugin: 'io.fabric'
android {
compileSdkVersion 15
buildToolsVersion "22.0.1"
defaultConfig {
applicationId "com.myapp"
minSdkVersion 15
targetSdkVersion 22
}
applicationVariants.all { variant ->
variant.outputs.each { output ->
def outputFile = output.outputFile
println outputFile
if (outputFile != null && outputFile.name.endsWith('.apk')) {
def manifestParser = new com.android.builder.core.DefaultManifestParser()
def version = manifestParser.getVersionName(android.sourceSets.main.manifest.srcFile)
def fileName = outputFile.name.replace('.apk', "-${version}.apk")
println fileName
output.outputFile = new File(outputFile.parent, fileName)
}
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
packagingOptions {
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/LICENSE.txt'
}
lintOptions {
abortOnError false
}
//Signing app
if(project.hasProperty("debugSigningPropertiesPath") && project.hasProperty("releaseSigningPropertiesPath")) {
File debugPropsFile = new File(System.getenv('HOME') + "/" + project.property("debugSigningPropertiesPath"))
File releasePropsFile = new File(System.getenv('HOME') + "/" + project.property("releaseSigningPropertiesPath"))
if(debugPropsFile.exists() && releasePropsFile.exists()) {
Properties debugProps = new Properties()
debugProps.load(new FileInputStream(debugPropsFile))
Properties releaseProps = new Properties()
releaseProps.load(new FileInputStream(releasePropsFile))
signingConfigs {
debug {
storeFile file(debugPropsFile.getParent() + "/" + debugProps['keystore'])
storePassword debugProps['keystore.password']
keyAlias debugProps['keyAlias']
keyPassword debugProps['keyPassword']
}
release {
storeFile file(releasePropsFile.getParent() + "/" + releaseProps['keystore'])
storePassword releaseProps['keystore.password']
keyAlias releaseProps['keyAlias']
keyPassword releaseProps['keyPassword']
}
}
buildTypes {
debug {
signingConfig signingConfigs.debug
}
release {
signingConfig signingConfigs.release
}
}
}
}
}
And I want to simplify it something like this
apply plugin: 'com.android.application'
apply plugin: 'io.fabric'
android {
compileSdkVersion 15
buildToolsVersion "22.0.1"
defaultConfig {
applicationId "com.myapp"
minSdkVersion 15
targetSdkVersion 22
}
include 'applicationVariants.gradle'
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
packagingOptions {
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/LICENSE.txt'
}
lintOptions {
abortOnError false
}
include 'signing.gradle'
}
You can include an an external build script. Check the official guide:
Just use:
apply from: 'signing.gradle'
i have done some thing like this.
in my libraries.gradle
ext {
//Android
targetSdkVersion = 22;
compileSdkVersion = 22;
buildToolsVersion = '22.0.1'
....
dagger2Version = '2.0'
butterknifeVersion = '6.1.0'
appCompatVersion = '22.2.0'
designVersion = '22.2.0'
recyclerViewVersion = '22.2.0'=
libraries = [
supportAnnotations: "com.android.support:support-annotations:${androidSupportAnnotationsVersion}",
googlePlayServices: "com.google.android.gms:play-services:${googlePlayServicesVersion}",
recyclerView : "com.android.support:recyclerview-v7:${recyclerViewVersion}",
picasso : "com.squareup.picasso:picasso:${picassoVersion}",
cardView : "com.android.support:cardview-v7:${cardViewVersion}",
appCompat : "com.android.support:appcompat-v7:${appCompatVersion}",
design : "com.android.support:design:${designVersion}",
findBugs : "com.google.code.findbugs:jsr305:${findbugsVersion}",
gson : "com.google.code.gson:gson:${gsonVersion}",
flow : "com.squareup.flow:flow:${flowVersion}",
butterknife : "com.jakewharton:butterknife:${butterknifeVersion}",
rxjava : "io.reactivex:rxjava:${rxjavaVersion}",
rxandroid : "io.reactivex:rxandroid:${rxandroidVersion}",
androidSupport : "com.android.support:support-v13:${androidSupportVersion}",
androidSupportV4: "com.android.support:support-v4:${androidSupportVersion}",
javaxInject : "javax.inject:javax.inject:${javaxInjectVersion}",
retrofit : "com.squareup.retrofit:retrofit:${retrofitVersion}",codec:${commonsCodecVersion}","com.facebook.stetho:stetho:${stethoVersion}",
apache : "org.apache.commons:commons-lang3:${apacheVersion}",
libPhoneNumber : "com.googlecode.libphonenumber:libphonenumber:$libPhoneNumber",
dagger2 : "com.google.dagger:dagger:${dagger2Version}",
dagger2Compiler : "com.google.dagger:dagger-compiler:${dagger2Version}",
javaxAnnotations : "javax.annotation:javax.annotation-api:${javaxAnnotationVersion}"
]
}
in my app.gradle
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile project(':logic')
compile project(':local-resources')
compile project(':api')
compile rootProject.ext.libraries.appCompat
compile libraries.design
compile rootProject.ext.libraries.recyclerView
compile rootProject.ext.libraries.butterknife
compile rootProject.ext.libraries.dagger2
compile libraries.rxandroid
compile libraries.stetho
compile libraries.cardView
compile libraries.picasso
apt rootProject.ext.libraries.dagger2Compiler
or apply from: rootProject.file('checkstyle.gradle')

Android Studio add jar library error

I have follow the instruction to add jar library but when i am going to synchronize the build grade then getting error.
Could not find property 'file' on org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler_Decorated#1a9bd9bb.
I am not getting what is error. please suggest.
build gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 22
buildToolsVersion "22.0.1"
defaultConfig {
applicationId "com.example.cws.myapplication"
minSdkVersion 11
targetSdkVersion 22
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
applicationVariants.all { variant ->
variant.outputs.each { output ->
output.outputFile = new File(file.parent, file.name.replace(".apk", "-" + defaultConfig.versionName + ".apk"));
}
}
}
sourceSets { main { res.srcDirs = ['src/main/res', 'src/main/res/layout'] } }
}
def var = dependencies {
compile 'com.android.support:appcompat-v7:22.0.0'
compile file 'libs/library-2.1.1.jar'
}
In Build.Gradle file the code to add the library is
compile files('libs/acra-4.6.0RC1.jar')
The letter 's' in 'files' is missing from the command.

Android Studio - automatically load support libraries

I'm getting frustrated with having to load the same support libraries over and over again each time I start a new project. Is there to make sure they're always loaded when starting Android Studio?
Thanks.
[Edit] I just found a library from jack wharton doing what you are looking for. Check SDK Manager Plugin : https://github.com/JakeWharton/sdk-manager-plugin
It exists for some libraries. You have to check on building your projects with Graddle in Android-Studio :
Tips for Graddle
App generator with included libraries
Graddle Test project that loads it automatically (for example only)
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.13.+'
}
}
// Manifest version information!
def versionMajor = 1
def versionMinor = 0
def versionPatch = 0
def versionBuild = 0
apply plugin: 'com.android.application'
repositories {
jcenter()
}
dependencies {
compile 'com.android.support:support-v4:20.+'
compile 'com.android.support:support-annotations:20.+'
compile fileTree(dir: 'libs', include: ['*.jar'])
}
def gitSha = 'git rev-parse --short HEAD'.execute([], project.rootDir).text.trim()
def buildTime = new Date().format("yyyy-MM-dd'T'HH:mm'Z'", TimeZone.getTimeZone("UTC"))
android {
compileSdkVersion 20
buildToolsVersion "19.1.0"
defaultConfig {
minSdkVersion 15
targetSdkVersion 20
versionCode versionMajor * 10000 + versionMinor * 1000 + versionPatch * 100 + versionBuild
versionName "${versionMajor}.${versionMinor}.${versionPatch}"
buildConfigField "String", "GIT_SHA", "\"${gitSha}\""
buildConfigField "String", "BUILD_TIME", "\"${buildTime}\""
}
signingConfigs {
release {
storeFile file(storeFilePath)
storePassword keystorePassword
keyAlias storeKeyAlias
keyPassword aliasKeyPassword
}
}
buildTypes {
debug {
applicationIdSuffix '.dev'
versionNameSuffix '-dev'
}
release {
signingConfig signingConfigs.release
}
}
lintOptions {
abortOnError false
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
}
You can set Android Studio to work offline if have loaded the supported libraries once;
Open Setting menu and search Gradle as keywords check on the Offline work :
Do remember to uncheck the checkbox if you have changed the your dependency in build.gradle

Android studio uses wrong file path to apk when I use custom build.gradle file

So Im trying to use a custom build file that generates an unsigned apk then runs a task on it and then zipaligns it. I havent gotten that working yet. However I do have it creating and properly signing the apk but when I try to just push the play button to run it in debug on a device using my custom debug set up studio/gradle generates my apk and places it in the directory I want but it fails to push it on to the device because it uses a file path that doesnt exist.
I/O Error: C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Android Studio\apk\V2.5-10-debug-20140922-2335.apk (The system cannot find the path specified). Is this hard coded into the studio build because I cant find a setting to change it. Its really making the whole process a real pain lol. Infact that path doesnt exist anywhere on my machine.
EDIT heres my build.gradle file
import java.text.SimpleDateFormat
import java.util.regex.Pattern
apply plugin: 'com.android.application'
def buildTime() {
def df = new SimpleDateFormat("yyyyMMdd'-'HHmm")
df.setTimeZone(TimeZone.getDefault())
return df.format(new Date())
}
def apkName = "MyApp"
def apkLocation
task (runApkSigTool , dependsOn: android, type: JavaExec) {
classpath files('apksigtool.jar')
main 'com.widevine.tools.android.apksigtool.ApkSigTool'
args[0] = apkLocation
args[1] = 'private_key.der'
args[2] = 'my.crt'
System.out.println(apkLocation);
}
android {
compileSdkVersion 19
buildToolsVersion "19.1.0"
signingConfigs{
debug{
storeFile file("debug.keystore")
storePassword "android"
keyAlias "androiddebugkey"
keyPassword "android"
}
release{
storeFile file("debug.keystore")
storePassword "android"
keyAlias "androiddebugkey"
keyPassword "android"
}
}
buildTypes {
debug{
}
release {
signingConfig signingConfigs.release
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
assembleDebug.doLast{
runApkSigTool.execute()
}
zipAlign true
}
debug{
signingConfig signingConfigs.debug
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
assembleDebug.doLast{
runApkSigTool.execute()
}
zipAlign false
}
android.applicationVariants.all { variant ->
def manifestFile = file("C:\\path\\app\\src\\main\\AndroidManifest.xml")
def pattern = Pattern.compile("versionName=\"(.+)\"")
def manifestText = manifestFile.getText()
def matcher = pattern.matcher(manifestText)
matcher.find()
def versionName = matcher.group(1)
pattern = Pattern.compile("versionCode=\"(.+)\"")
matcher = pattern.matcher(manifestText)
matcher.find()
def versionCode = matcher.group(1)
if (variant.zipAlign) {
variant.outputFile = new File("apk/"+apkName+"-V"+versionName+"-"+versionCode+"-"+variant.name+"-"+buildTime()+"-unaligned.apk");
variant.zipAlign.inputFile = variant.outputFile
variant.zipAlign.outputFile = new File("apk/"+apkName+"-V"+versionName+"-"+versionCode+"-"+variant.name+"-"+buildTime()+".apk");
} else {
apkLocation = "apk/"+apkName+"-V"+versionName+"-"+versionCode+"-"+variant.name+"-"+buildTime()+".apk";
variant.outputFile = new File("apk/"+apkName+"-V"+versionName+"-"+versionCode+"-"+variant.name+"-"+buildTime()+".apk");
System.out.println("CREATED UNSIGNED APK---------------")
}
}
}
lintOptions {
abortOnError false
ignoreWarnings true
checkAllWarnings false
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:20.0.0'
compile 'com.android.support:mediarouter-v7:20.0.0'
compile 'com.google.android.gms:play-services:5.0.89'
}
installDebug is calling buildTime() too when preparing the adb push command so the dates would mismatch with every minute.

Categories

Resources