Is it possible to use Jenkins for Flutter? - android

Is it possible to create pipeline for build release to play store using Jenkins with Flutter? I need to build a release for production/dev to play store.

It is possible, the easiest way to do this is to use a tool like Fastlane that integrates with Jenkins. I have used Fastlane myself and it's just incredible the amount of time it can save. It has an amazing CLI that can scaffold a deploy for you.
It has integrations with Jenkins https://docs.fastlane.tools/best-practices/continuous-integration/jenkins/
Example Fastfile file:
private_lane :push_test_flight do
sync_code_signing # Handles certificates
increment_build_number(
build_number: "1.2.5"
)
increment_version_number(
version_number: "1.0.0"
)
build_app(workspace: ENV["WORKSPACE"], scheme: "Example App")
upload_to_testflight(
reject_build_waiting_for_review: true,
demo_account_required: true,
beta_app_feedback_email: "some#mail-o.co",
beta_app_description: "A proof of concept app",
notify_external_testers: false,
changelog: "POC Updates",
beta_app_review_info: {
contact_email: "some#mail-o.co",
contact_first_name: "Some",
contact_last_name: "Mail",
contact_phone: "5558675309",
demo_account_name: "demo#mail.com",
demo_account_password: "demo#mail",
notes: "A proof of concept app"
},
)
end
This will manage my iOS distribution certificates, build the app with XCode and then push to testFlight!

Related

Use Firebase In-App-Messaging in Expo Project

I'm trying to add in a built-in application with react-native-expo a series of tools from firebase.I managed to add the following features Cloud Messaging and Firebase Analitycs.But I have to integrate In-app-messaging and Dynamic links
First time I install all firebase module/dependencies to do this task.
"#react-native-firebase/app": "^12.9.3",
"#react-native-firebase/in-app-messaging": "^12.9.3",
and my file looks like:
.......
import inAppMessaging from '#react-native-firebase/in-app-messaging
.......
useEffect(()=>{
await inAppMessaging().setMessagesDisplaySuppressed(true);
}[])
but I recive a warning:
]Unhandled promise rejection: Error: You attempted to use a firebase module that's not installed on your Android project by calling firebase.app().
After that I try to find a solution,I learn that expo allow to create plugins to extend expo functionality
I tty to salve problem fallow expo documentation but I couldn't figure out how to create these plugins.
Next I find a module that can help me with-rn-firebase but is not working and the module is depeciated.
Then I searched the internet until I discovered other people with the same problem this is the link I see in their app.json a basic config of plugin and I try to implement in my project,after I install dependencies that I need i add in my file:
"plugins": [
"#react-native-firebase/app",
"#react-native-firebase/analytics",
"#react-native-firebase/in-app-messaging"
],
But the fallowing error occure:
Package "#react-native-firebase/analytics" does not contain a valid config plugin.
Learn more: https://docs.expo.io/guides/config-plugins/#creating-a-plugin
Cannot use import statement outside a module
What I mean is, if anyone has ever faced this problem, I want in my project to be able to use in-app-messaging and dynamyc-links if someone has tried an implementation with expo and has any idea
Eventually I solved the problem,expo when I use the command expo:build android it only compiles my javascript files,but some of the code was written in java and other optional files in the android / ios folder.So instead of compiling with expo I used eas.
Faloowing command:
Run as administrator cmd and write this line npm install -g eas-cli.
Initialize new module in your expo/react native project with this line eas init.
Build aplication using this line for android: eas build --platform android
*For ios is a bit different you mast edit your file eas.json:
{
"cli": {
"version": ">= 0.43.0"
},
"build": {
"development": {
"distribution": "internal",
"android": {
"gradleCommand": ":app:assembleDebug"
},
"ios": {
"buildConfiguration": "Debug"
}
},
"preview": {
"distribution": "internal"
},
"production": {
"ios": {
"cocoapods": "1.11.2"
}
}
},
"submit": {
"production": {}
}
}
Build aplication using this line for ios: eas build --platform ios
Eas build include in complile all app file .gradle/.js/.java/.xml/.m/.h and this thing offer your posibility to build mobile app in expo with same functionality and complexity like react native cli.
Usefull Link
https://docs.expo.dev/build/setup/
React Native Expo Build Failing due to cocoapods version
I think you need to run locally using expo dev client
https://docs.expo.dev/development/getting-started/
Mostly, the package that is not supported by expo can run natively. But you need successfully built in eas build.

How can i specify the app (created in the Google Play Console) i want to update using Fastlane?

I'm currently trying to setup continuous integration with help of "Fastlane".
The Project is ready to be build and uploaded to the Google Play Store. If I do this manually everything works fine.
We want to have three different Apps in Google Play (with three different identifiers [com.myapp, com.myapp.int, com.myapp.rc]). With only one of them being public. The reason behind that is to be able to install every environment on one device for testing purposes. This is of course not the most elegant way of achieving this. But I believe that it's the only one and probably not without reasons.
So I'm able to build the app for different environments. The problem I'm currently facing is that if I want to upload them using Fastlane I'm only able to upload the one with the identifier com.myapp the other ones get the following error message:
[10:57:14]: fastlane finished with errors
[!] Google Api Error: forbidden: APK has the wrong package name. - APK has the wrong package name.
This sounds reasonable as I have never specified which app i want to update. If I manually upload the AAB I navigate to the right app inside the "Google Play Console" and upload it there but it seems that this option is not present in Fastlane (which would be pretty weird).
It is also weird that only one of them works as I wasn't even able to chose which one should work. How is Google/Fastlane choosing which App i want to update?
First i thought that the app would be specified inside the json key for google play. But I read in this medium post that it would be the same one across different projects.
Here is my Fastfile:
default_platform(:android)
platform :android do
desc "Runs all the tests"
lane :test do
gradle(task: "test")
end
desc "Submit a new Beta Build to Play Store"
lane :beta do
sh("cp", "../../.env.integration", "../../.env")
gradle(task: 'clean')
gradle(
task: 'bundle',
build_type: 'Release',
print_command: false,
)
upload_to_play_store(
track: 'internal'
)
end
end
And here is my Appfile:
json_key_file("~/.private_keys/google_api_key.json")
package_name("com.myapp")
for_platform :android do
for_lane :beta do
package_name("com.myapp.int")
end
end
The package_name() function you call in your Appfile will specify which App in Google Play fastlane should try to update.
However it does not determine the applicationId which gradle uses to build the App, so you have to make sure that these two values match.
This is how we solved it:
lane :build_lane do
slack(message: "Starting build for myapp", default_payloads:[])
build_android kFlavour:"myapp1" , kPackage_name:"com.abc.def"
end
With this part:
lane :build_android do | options |
sh("flutter", "build", "appbundle", "--flavor", options[:kFlavour], "--no-sound-null-safety")
slack(message: "Uploading " + options[:kFlavour] + " to playstore", default_payloads:[])
upload_to_play_store(
track: 'internal',
track_promote_to:'alpha',
version_code: flutter_version()["version_code"],
version_name: flutter_version()["version_name"] + '+' + flutter_version()["version_code"],
aab: "../build/app/outputs/bundle/"+options[:kFlavour]+"Release/app-" + options[:kFlavour] + "-release.aab",
skip_upload_changelogs: true,
skip_upload_screenshots: true,
skip_upload_images: true,
package_name: options[:kPackage_name],
)
slack(message: options[:kFlavour] + " successfully released on Android!", default_payloads:[])
end
We added the package_name line in the upload_to_play_store()
According to the documentation, you can specify the path to an APK or AAB through the apk or aab parameter.
In your example you should be able to upload a specific android app bundle like this (replace PATH_TO_AAB.aab with actual relative or absolute path to the file):
upload_to_play_store(
track: 'internal',
aab: 'PATH_TO_AAB.aab'
)
Alternative
Alternatively, you can create three different lanes for the three app versions you have.
In each lane you can then specify which flavor must be build in the gradle task.
For example if one of your flavors / versions has the name "pro", you can set the build_type in the gradle command to ProRelease instead of Release. This way, only the release version of the specific flavor is built.
desc "Submit a new Beta Build to Play Store"
lane :beta do
releaseFilePath = File.join(Dir.pwd, "..", "keystores","my-release-key.keystore")
gradle(task: 'clean')
gradle(
task: 'bundle',
build_type: 'ProRelease',
print_command: false,
)
upload_to_play_store(
track: 'internal'
)
end

App not found when migrating to appcenter from hockeyapp

I have an app that I build on CI using fastlane and I publish on HockeyApp.
I'm already accessing the build on AppCenter and everything is fine.
Now, I want to replace the call to the hockey plugin in the fastfile with a call to appcenter_upload.
The appcenter_upload asks me to define owner_name and app_name.
What I have seen is that these values are then used to build a URI:
https://appcenter.ms/orgs/{owner_name}/apps/{app_name}
When I open the app in AppCenter I can read that parts of the URI.
https://appcenter.ms/orgs/mobile-XXXX/apps/MyApp-Name
I tried to use
owner_name=mobile-XXXX
app_name=MyApp-Name
This was the code with hockey-app
hockey(
api_token: HOCKEYAPP_TOKEN,
apk: "path/to/apk",
notes: notes,
status: "2",
notes_type: "1",
teams: team,
commit_sha: `git rev-parse HEAD`.strip,
strategy: "add"
)
This is the code with appcenter_upload
ENV["APPCENTER_DISTRIBUTE_RELEASE_NOTES_CLIPPING"] = notes
appcenter_upload(
owner_name: "mobile-XXX",
app_name: "MyApp-Name,
api_token: HOCKEYAPP_TOKEN,
apk: "path/to/apk",
group: team
)
I was expecting this to be enough to publish directly in appcenter but the appcenter_plugin tells me that the app can't be found and asks me whether I want to create a new one.
I don't want to create another one.
This is the message I get:
Error 401: {"message"=>"12345678-abcd-ef01-994a-0123456789ab", "statusCode"=>401, "code"=>"Unauthorized"}
App with name MyApp-Name not found, create one? (y/n)

hockeyapp plugin and jenkins pipeline and hockey app URL

I am using a declarative pipeline and in a stage I have a step using Hockey app to upload an APK. It works fine, but I can not seem to get the URL to the HockeyApp version. Supposedly its in an environment var HOCKEYAPP_INSTALL_URL, but alas, it is not. My question is how to get this URL to the version in HocekyApp?
step([$class: 'HockeyappRecorder',
applications: [[downloadAllowed: false, mandatory: false,
notifyTeam: false, releaseNotesMethod: [$class: 'NoReleaseNotes'],
uploadMethod: [$class: 'AppCreation', publicPage: false]]],
debugMode: false, failGracefully: false])

Deploy Android app to Crashlytics built with React Native based on environment using fastlane

I tried to deploy an android app built with React Native to Crashlytics with fastlane. I was able to deploy, but by default it chose the staging version. I was wondering how I can specify to deploy the dev version (app-dev-release.apk). I've done some research but haven't found a good way yet. Below is the code
desc "Submit a new Beta Build to Crashlytics Beta"
lane :dev do
gradle(task: "assembleRelease")
crashlytics(
api_token: "[api_token]",
build_secret: "[build_scret]"
)
end
It turns out I can specify the apk_path in fastfile when configuring crashlytics
desc "Submit a new Beta Build to Crashlytics Beta"
lane :dev do
gradle(task: "assembleRelease")
crashlytics(
api_token: "[api_token]",
build_secret: "[build_scret]",
apk_path: "app/build/outputs/apk/app-dev-release.apk"
)
end

Categories

Resources