I have a UIAutomator test that interacts with the OS to automate some tasks that I can't do from ADB or another app. Sometimes I release a new version of the tests. I planned on using adb shell dumpsys package my.package.test | grep versionName to parse the version from the test app, and update it if necessary.
However, it appears that dumpsys package returns versionName=null for my UIAutomator test (built using a gradle script near-identical to the sample).
Right now I'm just overwriting the test every time I need it. Is there some way to embed version information in a UIAutomator test APK?
There's no version information in the default manifest generated for the test APK, then you have to introduce it.
1.
add this to your build.gradle:
defaultConfig {
manifestPlaceholders = [ versionName:versionName, versionCode:versionCode]
}
2.
copy your main AndroidManifest.xml to src/androidTest
3.
edit the test manifest
<!--suppress AndroidDomInspection -->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="your.package.name"
android:versionCode="${versionCode}"
android:versionName="${versionName}"
>
<application
tools:node="remove"
... >
</application>
</manifest>
4.
Once rebuilt, your test APK will include version information.
Related
React native application. Despite having entered in the manifest android:exported="true" i still have this problem in the build phase. It almost seems that some installed plugins did not insert it.
I read in some posts that proposed as a temporary solution to downgrade to version 30 of the android SDK, but i cannot because with that version it does not allow me to compile.
React Native 0.68
Android SDK version 33
Android Gradle Plugin version 7.3.0
From Merged Manifest
Error: android:exported needs to be explicitly specified for element <activity#androidx.test.core.app.InstrumentationActivityInvoker$EmptyActivity>. Apps targeting Android 12 and higher are required to specify an explicit value for android:exported when the corresponding component has an intent filter defined. See https://developer.android.com/guide/topics/manifest/activity-element#exported for details. mobile_app.app debug manifest, line 26 Error: android:exported needs to be explicitly specified for element <activity#androidx.test.core.app.InstrumentationActivityInvoker$EmptyFloatingActivity>. Apps targeting Android 12 and higher are required to specify an explicit value for android:exported when the corresponding component has an intent filter defined. See https://developer.android.com/guide/topics/manifest/activity-element#exported for details. mobile_app.app debug manifest, line 33
Based on the response from Aleja Duque-Torres, here's a temporary solution by adding the following code segment to your AndroidManifest.xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="...your package name"
xmlns:tools="http://schemas.android.com/tools"> <!-- ADD THIS LINE -->
<!-- Other Content -->
<application
.../>
<!-- ADD STARTS HERE -->
<activity
android:name="androidx.test.core.app.InstrumentationActivityInvoker$BootstrapActivity"
android:exported="false"
tools:replace="android:exported"/>
<activity
android:name="androidx.test.core.app.InstrumentationActivityInvoker$EmptyActivity"
android:exported="false"
tools:replace="android:exported"/>
<activity
android:name="androidx.test.core.app.InstrumentationActivityInvoker$EmptyFloatingActivity"
android:exported="false"
tools:replace="android:exported"/>
<!-- ADD ENDS HERE -->
</application>
</manifest>
Then do a build folder clean and run the project again. Hope this helps!
P.s. my guess is that this problem is due to some dependency package getting messed up. If someone else has any insight please feel free to shed some light on it!
solution:
In Git-bash run: * ./gradlew assembleDebug --stacktrace --info | tee my-logs.txt
Search "InstrumentationActivityInvoker"
Open file and add android:exported="true" on activity
Same issue, But I can't know the reason for it. It happens when I have updated macos, Do you have any information?
I am working with Java source code with TestNG and frequently see errors like no test found to run OR Test event were not received whenever I try to run test cases in IntelliJ IDEA.
Which I can fix with changing Build and run using IntelliJ IDEA from Gradle.
I am looking for alternative way using which can add this somewhere as configuration instead of going and changing this manually.
You can use gradle-idea-ext-plugin to set build and run actions right in the Gradle build script:
import static org.jetbrains.gradle.ext.ActionDelegationConfig.TestRunner.CHOOSE_PER_TEST
plugins {
...
id "org.jetbrains.gradle.plugin.idea-ext" version "1.0"
...
}
idea.project.settings {
delegateActions {
delegateBuildRunToGradle = true // Delegate Run/Build to Gradle
testRunner = CHOOSE_PER_TEST // Test execution: PLATFORM, GRADLE or CHOOSE_PER_TEST
}
}
But actually, the fact that it works with IDE runner, but does not work with Gradle runner may indicate problems. I would first check if it works from the command line Gradle - make sure you run the same test with it as from the IDE. If it works in terminal but does not work in IDE, I would report a bug at YouTrack with reproducible sample.
I am running React-Native 0.63.4 and encountering the following error:
Execution failed for task ':app:generateDebugBuildConfig'.
> Failed to calculate the value of task ':app:generateDebugBuildConfig' property 'buildConfigPackageName'.
> Failed to query the value of property 'packageName'.
> java.lang.NumberFormatException: For input string: "1.0.0"
This occurs when running npm run android, shortly after Gradle is done configuring the app and tries to execute it.
This error occurs both when I run the command from the root folder of the project as well as from the /android/ subfolder.
I did a gradlew clean but it is not helping.
Edit:
If I go in my /android/ folder and run gradlew android, the build will complete without error.
It is only when I run npm run android that this error shows up.
Here's another solution:
It's possible the xmls:tools is missing from android/app/src/main/AndroidManifest.xml folder. So you'll need to add that back.
<manifest xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" package="com.<buildname>">
This should be the first line at the top of your Manifest.xml.
I finally figured it out.
on the file: android/app/src/main/AndroidManifest.xml
The content began by:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.MyBusiness.MyApp"
android:versionCode="1.0.0"
android:versionName="1.0.0">
The versionCode has to be an integer: Only digits allowed. Apparently it does not matter what it is as it will increment whatever number we put.
Changing this to a number solved my problem:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.MyBusiness.MyApp"
android:versionCode="1000"
android:versionName="1.0.0">
I want to put break point on my generator code, but I don't know how to run the command on the debug mode.
I wrote generator using source_gen and build_runner
class MyGenerator extends GeneratorForAnnotation<Todo> {
#override
FutureOr<String> generateForAnnotatedElement(
Element element, ConstantReader annotation, BuildStep buildStep) {
return "// Hey! Annotation found!";
}
}
run commad flutter packages pub run build_runner build*
copy build.dart to root folder of project
add new run configuration
run debug, now you can debug your code generator!
* the packages is optional, you can just run flutter pub run build_runner build
Ivan's answer worked for me, but every time I changed a file that was using an annotation - the build process outputted:
[SEVERE] Terminating builds due to build script update
[INFO] Terminating. No further builds will be scheduled
and then renamed the build script itself from build.dart to build.dart.cached, and then exit with code 75.
After digging through the build_runner code, I discovered that this behavior can be mitigated by using the following Program Arguments:
serve --skip-build-script-check
(i.e. instead of just serve as Ivan suggested).
There may be some negative consequences; in the build_runner source code, in options.dart, I saw this:
// For testing only, skips the build script updates check.
bool skipBuildScriptCheck;
How can I access the build number and VCS checkout number in a Gradle script executed by Teamcity?
In Ant I can use ${build.number} and ${build.vcs.number.1} respectively.
Thank you.
These are simply JVM system properties that TeamCity sets for the Ant/Gradle JVM. You can access them with the usual Java means, for example System.getProperty("build.number").
If you are developing Android application you can access build.number to update apk file name accordingly:
defaultConfig {
applicationId "com.mydemoci"
minSdkVersion 14
targetSdkVersion 23
versionCode 1
versionName "0.7"
ext.buildNumber = System.getProperty("build.number") ?: "Regular"
archivesBaseName = "$applicationId-v$versionName-b$buildNumber"
}
To test locally just run gradlew clean build -Dbuild.number=123
I tested with many cases with gradle and injecting build.number outside variables. In my case, I use docker as a build environment so teamcity-provided environment does not be injected successfully.
There are two possibilities to inject variables to gradle. Note that -D and -P differences in below example.
// 1. gradle build -Pbuild.number=555
aaa = rootProject.properties.get("build.number")
// 2. gradle bulid -Dbuild.number=444
bbb = System.getProperty("build.number")
gradle --help says [option] task as a command order but task [option] works.
An example build.gradle script is as below;
ext {
buildNumber = (rootProject.properties.get("build.number") as Integer) ?: 1
}
android {
defaultConfig {
versionCode project.buildNumber
versionName "1.3.7." + project.buildNumber.toString()
}
In my case, I want to use build.number as a android versionCode, so parsing to Integer is required with :? null treatment.
As of TeamCity 9.1.5 this is changed. "Properties" (both "system" and "teamcity" ) properties are set as project ext properties.
https://confluence.jetbrains.com/display/TCD9/Defining+and+Using+Build+Parameters+in+Build+Configuration
Very confusing when reading the overveiw page https://confluence.jetbrains.com/display/TCD9/Configuring+Build+Parameters#ConfiguringBuildParameters-ConfigurationParameters the use of "system" (in "system properties") had me thinking they were set as JVM System properites so I tried the Gradle mechanism as described here: https://docs.gradle.org/current/userguide/build_environment.html
which says to use "org.gradle.project." .. adding that with TeamCity that says to use "system." I tried to set a gradle property "repositoryUrl" as "system.org.gradle.project.repositoryUrl" ...
This didn't work. adding "properties" to the gradle command in team city showed that there was a gradle property called "org.gradle.project.repositoryUrl"
By trial and error I stumbled on the obvious ... and was about to report it as a docs bug .. but then found it in the documentation
Summary: In TeamCity 9.1.5+ use
system.<propertyName>
e.g.
system.repositoryUrl
In Gradle these are accessable as rootProject (or project) "properties" (not "system properties" ... e.g.
println repositoryUrl
println project.repositoryUrl
println rootProject.repositoryUrl
println project.properties["repositoryUrl"]
println rootProject.ext.repositoryUrl
println "${repositryUrl}"
assert hasProperty("repositoryUrl")
and the 500 other ways of doing the same thing.