Open supmanyu opened 2 years ago
We have the same need, is what @supmanyu is describing possible with this project?
Hi @andordavoti, I think i have managed to figure it out using the fastlane env cookbook by creating a hook like this:
const fs = require("fs");
const templates = require('./env_templates')
// ** function which will create files if they dont already exist, otherwise it will overwrite the contents of the file
function writeFileSyncRecursive(filename, content) {
let filepath = filename.replace(/\\/g, '/')
// -- preparation to allow absolute paths as well
let root = ''
if (filepath[0] === '/') {
root = '/'
filepath = filepath.slice(1)
} else if (filepath[1] === ':') {
root = filepath.slice(0, 3) // c:\
filepath = filepath.slice(3)
}
// -- create folders all the way down
const folders = filepath.split('/').slice(0, -1)
folders.reduce((acc, folder) => {
const folderPath = acc + folder + '/'
if (!fs.existsSync(folderPath)) {
fs.mkdirSync(folderPath)
}
return folderPath
}, root)
// -- write file
fs.writeFileSync(root + filepath, content)
}
module.exports = {
on_env: async function (env) {
writeFileSyncRecursive('android/app/proguard-rules.pro', templates(env).proguardConfig())
},
};
Created a env_templates.js
in the root directory like this:
module.exports = function (env) {
let module = {}
// ** android/app/proguard-rules.pro
module.proguardConfig = function () {
return `# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in /usr/local/Cellar/android-sdk/24.3.3/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the proguardFiles
# directive in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html
# Add any project specific keep options here:
-keep class com.facebook.jni.** { *; }
-keep class com.facebook.hermes.unicode.** { *; }
-keep public class com.horcrux.svg.** {*;}
-keep class com.facebook.react.turbomodule.** { *; }
# MeiZu Fingerprint
-keep class com.fingerprints.service.** { *; }
-dontwarn com.fingerprints.service.**
# Samsung Fingerprint
-keep class com.samsung.android.sdk.** { *; }
-dontwarn com.samsung.android.sdk.**
-keepattributes *Annotation*
-keepclassmembers class ** {
@org.greenrobot.eventbus.Subscribe <methods>;
}
-keep enum org.greenrobot.eventbus.ThreadMode { *; }
-keep class com.adjust.sdk.** { *; }
-keep class com.google.android.gms.common.ConnectionResult {
int SUCCESS;
}
-keep class com.google.android.gms.ads.identifier.AdvertisingIdClient {
com.google.android.gms.ads.identifier.AdvertisingIdClient$Info getAdvertisingIdInfo(android.content.Context);
}
-keep class com.google.android.gms.ads.identifier.AdvertisingIdClient$Info {
java.lang.String getId();
boolean isLimitAdTrackingEnabled();
}
-keep public class com.android.installreferrer.** { *; }
-keep class com.facebook.react.turbomodule.** { *; }
-keep class com.swmansion.reanimated.** { *; }
-keep public class com.dylanvann.fastimage.* {*;}
-keep public class com.dylanvann.fastimage.** {*;}
-keep public class * implements com.bumptech.glide.module.GlideModule
-keep public class * extends com.bumptech.glide.module.AppGlideModule
-keep public enum com.bumptech.glide.load.ImageHeaderParser$** {
**[] $VALUES;
public *;
}
-keep interface in.onedirect.** { *; }
-keep class in.onedirect.** { *; }
-keepclassmembers class ${env['BUNDLE_ID']}.BuildConfig {
public static <fields>;
}
`
}
return module
}
and adding the proguard-rules.pro
file to .gitignore
so that it gets generated by this library everytime. So far it has worked great, I have been able to access the env variables inside build.gradle
correctly. Do let me know if more help is needed.
In an app that I'm currently working on, there is a requirement to keep different package names for different branches, for e.g (com.xyz.master in master branch and com.xyz.staging in the staging branch), but to allow this amazing library to work with proguard we need to hardcode the Bundle ID. I'd be grateful if it someone could point me in the right direction to set up this library for my scenario.
Any help is greatly appreciated!