How to specify output .apk file path when using fastlane gradle? - fastlane

I have different product flavors of my app and I build them with fastlane. This is my fastfile:
default_platform(:android)
platform :android do
desc "Release apk with different urls"
lane :release do
gradle(
task: "assemble",
build_type: "release",
flavor: "flavorname",
print_command: true,
properties: {
"android.injected.signing.store.file" => "Key.jks",
"android.injected.signing.store.password" => "KeyPass",
"android.injected.signing.key.alias" => "KeyAlias",
"android.injected.signing.key.password" => "KeyPass"
}
)
end
end
The problem is apk files are created in project directory.
(projectname/app/build/outputs/apk/flavorname/release/app-flavorname-release.apk)
How to move this apk files to my Desktop automatically?

I use the following under my gradle call:
lane :release do
gradle(...)
APK_LOCATION = "#{lane_context[SharedValues::GRADLE_APK_OUTPUT_PATH]}"
sh("mv #{APK_LOCATION} ~/Desktop/")
end
The advantage of using the variable is that you will be able to use the same code for release and debug apk.
Cheers.

It doesn't seem that gradle has an option to specify the output.
What I suggest you is to add a command line just after the gradle is done to move this .apk to the Desktop or wherever you want.
sh "mv ../app/build/outputs/apk/release/app-release.apk path/to/Desktop"

You can also use fastlane action copy_artifacts instead of mv
lane :release do
gradle(...)
copy_artifacts(
artifacts: ['*/build/outputs/apk/**/*.apk'],
target_path: '~/Desktop/'
)
end
Wilcard */build/outputs/apk/**/*.apk will work with any build types, flavors app module name.
Or as said #janpio above, you can use variable GRADLE_APK_OUTPUT_PATH:
lane :release do
gradle(...)
copy_artifacts(
artifacts: [lane_context[SharedValues::GRADLE_APK_OUTPUT_PATH]],
target_path: '~/Desktop/'
)
end

Related

Increment Build & Version Number of Android App using Azure DevOps & App Centre

I am using Azure DevOps and AppCenter(Distribution) for implementing my CICD. Based on the steps mentioned below I have implemented the both CI & CD tasks.
Thant means,
I will create the build using Azure Devops (VSTS) & Push that in to App Centre.
Steps I Follow
Here my doubt is,
How I can increment my Build and Version numbers while distributing these builds?
The easy way is to install Mobile App Tasks for iOS and Android extension for Azure DevOps. You get a task "Bump Version" (for Andriod and iOS).
The task change app's version name and code at build time.
Inputs:
sourcePath - Path to android manifest
versionCode - code number that must be an integer (put the build number variable, it's incremented automatically)
versionCodeOffset - a specific number to increment the version code
versionName- user visible name
printFile - output the file before and after changing variables
Another option is to install Colin's ALM Corner Build & Release Tools extension and use the Version Assemblies task following this detailed tutorial.
Check also this question & answer.
For anyone still looking for an alternative method, try modifying either the version number, version name or both in the module build.gradle file like below:
android {
defaultConfig {
applicationId 'com.sample.testapp'
minSdk 28
targetSdk 31
versionCode 2
versionName "2.2"
}
...
}
You can do almost anything with shell scripting, but I figured out to Automate Build numbering & App versioning for Android WITHOUT shell scripting while using Microsoft AppCenter CI/CD pipelines!
You can create 2 environment variables VERSION_CODE & VERSION_NAME and then use them in the build.gradle file like this:
versionCode System.getenv("VERSION_CODE") ? System.getenv("VERSION_CODE").toInteger() : 201
versionName System.getenv("VERSION_NAME") ? System.getenv("VERSION_NAME").toString() : "1.2.1"
More details in this article
Another option (if you don't want to install an extra plugin in Azure) is using the embedded counter function.
So basically you'll need to create the variable in the root of your pipeline, smth. like this:
versionCode: $[counter('Google_Play_version_offset', 100)]
Then it will autoincrement for each build - 100, 101, 102, etc.
In the gradle task you can pass this value with next:
- task: Gradle#2
inputs:
...
options: '-PversionCode=$(versionCode)'
...
Please also make sure to handle this option in the build.gradle file.

Deploying .NET Core Application with Windows Compatibility Pack

I'm busy deploying a .NET Core 2.1 application into our testing environment, but I'm getting the following error.
Error:
An assembly specified in the application dependencies manifest (MyApp.deps.json) was not found:
package: 'System.Diagnostics.EventLog', version: '4.5.0'
path: 'runtimes/win/lib/netcoreapp2.1/System.Diagnostics.EventLog.dll'
We are using the Windows Compatibility Pack to access the Event Log.
I have the following item in the dependency Json file:
"System.Diagnostics.EventLog/4.5.0": {
"dependencies": {
"Microsoft.Win32.Registry": "4.5.0",
"System.Security.Permissions": "4.5.0",
"System.Security.Principal.Windows": "4.5.0",
"System.Threading.AccessControl": "4.5.0"
},
"runtime": {
"lib/netstandard2.0/System.Diagnostics.EventLog.dll": {
"assemblyVersion": "4.0.0.0",
"fileVersion": "4.6.26515.6"
}
},
"runtimeTargets": {
"runtimes/win/lib/netcoreapp2.0/System.Diagnostics.EventLog.dll": {
"rid": "win",
"assetType": "runtime",
"assemblyVersion": "4.0.0.0",
"fileVersion": "4.6.26515.6"
}
}
}
Please advise how one should deploy these dependencies. Also, what is the root folder to this relative path runtimes/win/lib/netcoreapp2.0?
We actually found a solution for our scenario:
- Our situation was that we tried to run a netcoreapp based test project on our test agent
- dotnet test on the project file worked
- dotnet vstest sometimes worked on the project output directory (we are not sure why and on which setup)
- dotnet vstest did run into the above error when run into an other directory & downloaded from CI
- dotnet vstest did run into an AssemblyNotFoundException on the test agent (which didn't make any sense for us)
The solution was to use dotnet publish for our test project and use the "self-contained" output to run on the test agent. dotnet publish copied the required runtimes/win/lib/netcoreappX.X/*.dll files into the publish output directory.
After a lot of testing, the key issue seems to be the "RuntimeIdentifiers". There is a visible option for this when you publish, but in order to use it when just building you need to add a couple of tags to your .csproj file.
The first is:
<RuntimeIdentifier>win-x86</RuntimeIdentifier>
This will cause NuGet to retrieve the correct dlls (change the value depending on your needs). For me I was compiling to platform x86. I don't know what NuGet was getting by default, but whatever it was had different file sizes for the same files.
You also should then add this tag:
<SelfContained>false</SelfContained>
or else your build will default to copying the entire framework.
Also note that using the RuntimeIdentifier tag will cause your default output folder to include the value you specified. For example my subfolder became:
Project\bin\x86\Debug\netcoreapp3.1\win-86\
For publishing you should be able to do something similar; the problem will be to match your RuntimeIdentifier to your platform. You shouldn't need to specify SelfContained unless you specifically need to.

How to remove default assets from ionic 2 build?

I am learning Ionic 2; writing code in Visual Studio code. I created project using following command:
> ionic start --v2 MyFirstIonic blank
And then
> cd MyFirstIonic
> ionic platform add android
When I build and run, > ionic run android, ionic creates assets folder in www directory and copies font files for Ionicons, Roboto, and Noto-sans, which are added in apk during build process. I'd like to exclude Ionicons, Roboto, and Noto-Sans from final build, and use FontAwesome files instead. How will I be able to achieve this?
You need to edit your node_modules/#ionic/app-scripts/copy.config.js.
Sample file here.
Remove copyFonts entry :
copyFonts: {
src: ['{{ROOT}}/node_modules/ionicons/dist/fonts/**/*', '{{ROOT}}/node_modules/ionic-angular/fonts/**/*'],
dest: '{{WWW}}/assets/fonts'
},
from the file. This copies the ionicon fonts to your www folder.
Also remove the assets you do not need from src/assets folder.
You can edit copy.config.js file to add any other assets into the build process.
Refer answers here.
I would suggest you delete the unnecessary files from:
[project]/node_modules/ionic-angular/fonts/
(Keep the ionicons.* files.)
You'll still have to do that every time you update ionic-angular but it's easier and less error prone than keeping track of changes to the app-scripts bundle.
Additionally, comment out the roboto and noto-sans imports in:
[project]/src/theme/variables.scss
--
If you still want to update the script then the right way to do that is to copy the file locally as [project]/src/webpack.config.js and add the following entry to your package.json:
"config": {
"ionic_webpack": "./webpack.config.js"
}
--
Hope that helps!

Build everything : even builtByDefault: false

I have a project that contain lots of references to other qbs file.
Project {
name: "MyProject"
references: ["SubProject1/SubProject1.qbs",
"SubProject2/SubProject2.qbs",
"SubProject3/SubProject3.qbs",
"SubProject4/SubProject4.qbs",
...
]
}
When working in QtCreator, I don't want to always buid everything, so some of the subProject are not built by default :
builtByDefault: false
I also have automated build tools that should built everything to make sure it does build.
The tools run commands like :
/opt/Qt5.5.1/Tools/QtCreator/bin/qbs build -d . -f ../MyProject/MyProject.qbs --job
Problem is this command doesn't build the subProject that are not build by default.
Is there a way to force it to build everything in command line ?
It is explained in the documentation : https://doc.qt.io/qbs/product-item.html
I simply needed to add --all-products
<qbs-folder>/qbs build --all-products -d . -f ../MyProject/MyProject.qbs

AzureDevOps/VSTS Build - Could not find version number data in BUILD_BUILDNUMBER

Setting up a simple class library to build and publish to VSTS's own feed, I see this error when the NuGet package runs.
Could not find version number data in BUILD_BUILDNUMBER
I have the "Use Build number to version package" option ticked. Expected VSTS to just work.
The tip for "Use Build number to version package" states:
Will use the build number to version you package. Under General set the build format to be '$(BuildDefinitionName)_$(Year:yyyy).$(Month).$(DayOfMonth)$(Rev:.r)'
Following this did get me past this issue (and on to a new one).
Default value:
[]
Correct Value:
[]
This is because your build number does not match the regex in "Nuget Packager" step. Following is the regex that nuget packager task used to find the build number. You can set your build number format base on this. General, the format like 1.2.3 or 1.2.3.4 would work.
Write-Verbose "Autoversion: Getting version number from build"
##Get Version from Build
# Regular expression pattern to find the version in the build number
# and then apply it to the assemblies
$VersionRegex = "\d+\.\d+\.\d+(?:\.\d+)?"
If what you want is the major.minor.patch.unique-to-build then you use the Use the date and time option.
In yaml, the equivalent is
- task: NuGetCommand#2
displayName: Pack
inputs:
command: 'pack'
packagesToPack: '**/*.csproj'
versioningScheme: 'byPrereleaseNumber'
majorVersion: '1'
minorVersion: '0'
patchVersion: '0'
I had a variable in my .nuspec file:
<tags>Build#$build$</tags>
that was incorrectly parameterized in the package build step. With the package step open in the build editor, I expanded the 'Advanced' section added to 'Additional Build Properties' this text
build=$(Build.BuildNumber)