I have a situation where I am having separate apps on AppCenter but all of the apps use same repo. So these different apps are just white label versions of the same app.
Now I am facing problem where I would like to change AppSecret per ios build config. But since AppCenter-Config.plist is custom plist file I cant use user defined variables with them. (https://stackoverflow.com/questions/34067120/use-user-defined-build-settings-in-custom-plist-file)
If however this SDK would read the app secret from Info.plist I would be able to use user defined variables. Is there any reason why app secret has to be in own plist file? Is there drawback if it would be in Info.plist?
@henrikra for a current work around you could add a pre-build script that replaces the AppCenter-Config.plist depending on the build. It will copy you old config for backup, then replace the current config with the one for your white label. I haven't tried this with AppCenter but used similar setups for white label apps or different stages (dev/prod).
Go to your project > select target > select build phases > New Run Script Phase (plus button) > Move it to before compiles (pre-build)
# Backing up original plist
cp AppCenter-Config.plist AppCenter-Config.plist.bak
if [ ${TARGET_NAME} = "WhiteLabel A" ]; then
echo "Setting AppCenter for WhiteLabel A"
cp AppCenter-Config-WhiteLabelA AppCenter-Config.plist
elif [ ${TARGET_NAME} = "WhiteLabel B" ]; then
echo "Setting AppCenter for WhiteLabel B"
cp AppCenter-Config-WhiteLabelB AppCenter-Config.plist
else
echo "Not specified"
fi
Even better you could save this as config_appcenter.sh and just call it in the prebuild for each target.
@hammadzz Yeah we did something similar. Only down side is that you will get unwanted changes to git because you are basically modifying file that is tracked by git
@henrikra you can make sure to undo the changes in the script by doing a post compile script that cleans up.
Thanks for the above, works great for iOS. Also trying to set it up on Android, but it looks like here that Android looks for the first appcenter-config.json file it finds or always looks in the main folder, but I have a debug folder and a beta folder for the other variants of our Android app. Any ideas how to either update the appcenter-config.json on build like above, or to tell AppCenter where to find those specific variant files?
Hi @CodyBrouwers,
App Center doesn't support specifying different build variants (we're tracking this as as feature request).
Maybe you can add a script that copies the right appcenter-config.json into the main folder based on what variant you are building?
You should be able to do this as a gradle task (check out the gradle docs for file operations), like this:
task copyAppCenterConfig(type: Copy) {
// maybe also delete the appcenter-config.json in main first?
from file("${buildDir}/path-to-your-beta-folder/appcenter-config.json")
into file("${buildDir}/path-to-main-folder/appcenter-config.json")
}
and run this before build?
@TroubleMakerBen that is a great idea, thanks so much for the quick response! I ended up doing this earlier today:
buildTypes {
debug {
if (getCurrentBuildType() == "debug") {
println "=========== Configuring appcenter-config.json for Development ==========="
def appCenterSecret = "..."
new File("$projectDir/src/main/assets/appcenter-config.json").text = "{ \"app_secret\": \"${appCenterSecret}\" }"
}
}
... // Same in the rest of my build types
}
Using the getCurrentBuildType method from this gist.
Using a task like you suggested might be a better approach though so thanks a lot for the recommendation!
this is our example:
if [ "$APPCENTER_BRANCH" == "master" ]
then
echo "Building with prod config"
cp "environments/config.prod.js" "src/services/config/index.js"
cp "environments/AppCenter-Config.prod.plist" "ios/NordstromON/AppCenter-Config.plist"
cp "environments/appcenter-config.prod.json" "android/app/src/main/assets/appcenter-config.json"
else
echo "Building with nonprod config"
cp "environments/config.nonprod.js" "src/services/config/index.js"
cp "environments/AppCenter-Config.nonprod.plist" "ios/NordstromON/AppCenter-Config.plist"
cp "environments/appcenter-config.nonprod.json" "android/app/src/main/assets/appcenter-config.json"
fi
@CodyBrouwers and @ElektrojungeMS I was able to get around this issue without any code in the gradle file that might be helpful
we have several product flavors (client1, client2) and build types (qa, release), so I was able to create a directory for each build variant that needed a different AppCenter config like this...
/android/app/src/client1Qa/assets/appcenter-config.json
/android/app/src/client1Release/assets/appcenter-config.json
/android/app/src/client2Qa/assets/appcenter-config.json
/android/app/src/client2Release/assets/appcenter-config.json
this allows you to have a default /android/app/src/main/assets/appcenter-config.json for any other build variant that doesn't need a specific api key.
@tkiefhaber getting this error with your suggested solution - `Found more than one appcenter-config.json. How did you fixed this?
You can have a appcenter-pre-build.sh in the root folder
#!/usr/bin/env bash
echo $CODE_PUSH_ANDROID_SECRET | base64 --decode > "$APPCENTER_SOURCE_DIRECTORY/android/app/src/main/assets/appcenter-config.json"
echo $CODE_PUSH_IOS_SECRET | base64 --decode > "$APPCENTER_SOURCE_DIRECTORY/ios/Shyn/AppCenter-Config.plist"
And for each environment, you can use a different file and base64 -w 0 appcenter-config.json and add as the env var.
Most helpful comment
@TroubleMakerBen that is a great idea, thanks so much for the quick response! I ended up doing this earlier today:
Using the
getCurrentBuildTypemethod from this gist.Using a task like you suggested might be a better approach though so thanks a lot for the recommendation!