Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jrichardsz/f0769943c6e0f88f51d8f43934c547b7 to your computer and use it in GitHub Desktop.
Save jrichardsz/f0769943c6e0f88f51d8f43934c547b7 to your computer and use it in GitHub Desktop.
android snippets

/acme-android/app/build.gradle

apply plugin: 'com.android.application'

android {
	compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    signingConfigs {
        release {
            storeFile = file(String.valueOf(System.getenv("ANDROID_BUILD_KEYSTORE_PATH")))
            keyAlias = String.valueOf(System.getenv("ANDROID_BUILD_KEY_ALIAS"))
            storePassword = String.valueOf(System.getenv("ANDROID_BUILD_KEYSTORE_PASSWORD"))
            keyPassword = String.valueOf(System.getenv("ANDROID_BUILD_KEY_PASSWORD"))
        }
        debug {
            storeFile = file(String.valueOf(System.getenv("ANDROID_BUILD_KEYSTORE_PATH")))
            keyAlias = String.valueOf(System.getenv("ANDROID_BUILD_KEY_ALIAS"))
            storePassword = String.valueOf(System.getenv("ANDROID_BUILD_KEYSTORE_PASSWORD"))
            keyPassword = String.valueOf(System.getenv("ANDROID_BUILD_KEY_PASSWORD"))
        }
    }
    useLibrary 'org.apache.http.legacy'

    packagingOptions {
        exclude 'META-INF/DEPENDENCIES'
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/license.txt'
        exclude 'META-INF/NOTICE'
        exclude 'META-INF/NOTICE.txt'
        exclude 'META-INF/notice.txt'
        exclude 'META-INF/ASL2.0'
    }

    compileSdkVersion 29
    buildToolsVersion "29.0.0"
    defaultConfig {
        applicationId "com.utec.serviciosgenerales"
        minSdkVersion 21
        targetSdkVersion 29
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
        signingConfig signingConfigs.release
    }
    buildTypes {

        release {
            debuggable true
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
						resValue 'string', 'MY_VAR_1', String.valueOf(System.getenv("MY_VAR_1"))
            buildConfigField "int", "MY_VAR_2", System.getenv("MY_VAR_2")            
        }
				debug {
						resValue 'string', 'MY_VAR_1', String.valueOf(System.getenv("MY_VAR_1"))
            buildConfigField "int", "MY_VAR_2", System.getenv("MY_VAR_2") 
		    }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'androidx.appcompat:appcompat:1.0.2'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    implementation 'androidx.legacy:legacy-support-v4:1.0.0'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test:runner:1.2.0'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
    implementation 'com.squareup.retrofit2:retrofit:2.5.0'
    implementation 'com.squareup.retrofit2:converter-gson:2.4.0'
    implementation 'com.github.bumptech.glide:glide:4.9.0'
    implementation 'androidx.recyclerview:recyclerview:1.0.0'
    implementation 'com.google.android.gms:play-services-auth:17.0.0'
    implementation 'com.itlgl:iosdialog:1.0.1'
    implementation 'de.hdodenhof:circleimageview:3.0.0'
    implementation 'com.android.volley:volley:1.1.1'

    implementation('org.apache.httpcomponents:httpmime:4.3') {
        exclude module: 'httpclient'
    }
    implementation 'org.apache.httpcomponents:httpclient-android:4.3.5'
}

Usage

import com.utec.serviciosgenerales.R;
import com.utec.serviciosgenerales.BuildConfig;

//int
BuildConfig.MY_VAR_2

//string
context_or_view.getResources().getString(R.string.MY_VAR_1);

https://www.tanelikorri.com/tutorial/android/set-variables-in-build-gradle/

  • create gcp project in console developers

  • create a jks and register in the same gcp project as android OAuth client ID

    • this value is required by android to use internal s.o services
    • this value must be used to sign the apk : signingConfigs in build.graddle
  • in the same gcp project, create an WEB OAuth client ID

    • you will get a client id and client secret
    • origin and redirect are not required
    • origin and redirect accepts any string value with http url format
    • origin and redirect empty or with value are required to exchange the oauth code by an access_token:
https://accounts.google.com/o/oauth2/token
 ?code={authorization_code}
 &client_id={client_id}
 &client_secret={client_secret}
 &redirect_uri={redirect_uri}
 &grant_type=authorization_code 
 
Content-Type : application/x-www-form-urlencoded
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment