How to use withCompileSdkVersion method of io.appium.java_client.android.options.server.EspressoBuildConfig class

Best io.appium code snippet using io.appium.java_client.android.options.server.EspressoBuildConfig.withCompileSdkVersion

Run io.appium automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

EspressoBuildConfig.java

Source: EspressoBuildConfig.java Github

copy
1/*
2 * Licensed under the Apache License, Version 2.0 (the "License");
3 * you may not use this file except in compliance with the License.
4 * See the NOTICE file distributed with this work for additional
5 * information regarding copyright ownership.
6 * You may obtain a copy of the License at
7 *
8 *     http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package io.appium.java_client.android.options.server;
18
19import io.appium.java_client.internal.CapabilityHelpers;
20import io.appium.java_client.remote.options.BaseMapOptionData;
21
22import java.util.HashMap;
23import java.util.List;
24import java.util.Map;
25import java.util.Optional;
26
27public class EspressoBuildConfig extends BaseMapOptionData<EspressoBuildConfig> {
28    public static final String TOOLS_VERSION = "toolsVersions";
29    public static final String ADDITIONAL_APP_DEPENDENCIES = "additionalAppDependencies";
30    public static final String ADDITIONAL_ANDROID_TEST_DEPENDENCIES
31            = "additionalAndroidTestDependencies";
32
33    public EspressoBuildConfig() {
34        super();
35    }
36
37    public EspressoBuildConfig(String json) {
38        super(json);
39    }
40
41    private EspressoBuildConfig assignToolsVersionsField(String name, Object value) {
42        Optional<Map<String, Object>> toolsVersionsOptional = getOptionValue(TOOLS_VERSION);
43        Map<String, Object> toolsVersions = toolsVersionsOptional.orElseGet(HashMap::new);
44        toolsVersions.put(name, value);
45        if (!toolsVersionsOptional.isPresent()) {
46            assignOptionValue(TOOLS_VERSION, toolsVersions);
47        }
48        return this;
49    }
50
51    private <R> Optional<R> getToolsVersionsFieldValue(String name) {
52        Optional<Map<String, Object>> toolsVersionsOptional = getOptionValue(TOOLS_VERSION);
53        //noinspection unchecked
54        return toolsVersionsOptional.map((v) -> (R) v.getOrDefault(name, null));
55    }
56
57    /**
58     * Set Gradle version.
59     * By default, the version from the build.gradle is used.
60     *
61     * @param version E.g. "6.3".
62     * @return self instance for chaining.
63     */
64    public EspressoBuildConfig withGradleVersion(String version) {
65        return assignToolsVersionsField("gradle", version);
66    }
67
68    /**
69     * Get Gradle version.
70     *
71     * @return Gradle version.
72     */
73    public Optional<String> getGradleVersion() {
74        return getToolsVersionsFieldValue("gradle");
75    }
76
77    /**
78     * Set Gradle plugin version. It must correspond to the Gradle version
79     * (if provided). By default, the version from the build.gradle is used.
80     *
81     * @param version E.g. "4.1.1"
82     * @return self instance for chaining.
83     */
84    public EspressoBuildConfig withAndroidGradlePluginVersion(String version) {
85        return assignToolsVersionsField("androidGradlePlugin", version);
86    }
87
88    /**
89     * Get Gradle plugin version.
90     *
91     * @return Gradle plugin version.
92     */
93    public Optional<String> getAndroidGradlePluginVersion() {
94        return getToolsVersionsFieldValue("androidGradlePlugin");
95    }
96
97    /**
98     * Set Android build tools version to compile the server with.
99     * By default, the version from the build.gradle is used.
100     *
101     * @param version E.g. "28.0.3".
102     * @return self instance for chaining.
103     */
104    public EspressoBuildConfig withBuildToolsVersion(String version) {
105        return assignToolsVersionsField("buildTools", version);
106    }
107
108    /**
109     * Get Android build tools version.
110     *
111     * @return Android build tools version.
112     */
113    public Optional<String> getBuildToolsVersion() {
114        return getToolsVersionsFieldValue("buildTools");
115    }
116
117    /**
118     * Set Android SDK version to compile the server for.
119     * By default, the version from the app build.gradle is used.
120     *
121     * @param version E.g. "28"
122     * @return self instance for chaining.
123     */
124    public EspressoBuildConfig withCompileSdkVersion(String version) {
125        return assignToolsVersionsField("compileSdk", version);
126    }
127
128    /**
129     * Get the target Android SDK version.
130     *
131     * @return Android SDK version.
132     */
133    public Optional<String> getCompileSdkVersion() {
134        return getToolsVersionsFieldValue("compileSdk");
135    }
136
137    /**
138     * Set the minimum Android SDK version to compile the server for.
139     * By default, the version from the app build.gradle is used.
140     *
141     * @param apiLevel E.g. 18.
142     * @return self instance for chaining.
143     */
144    public EspressoBuildConfig withMinSdk(int apiLevel) {
145        return assignToolsVersionsField("minSdk", apiLevel);
146    }
147
148    /**
149     * Get the minimum Android SDK version.
150     *
151     * @return Minimum Android SDK version.
152     */
153    public Optional<Integer> getMinSdkVersion() {
154        Optional<Object> result = getToolsVersionsFieldValue("minSdk");
155        return result.map(CapabilityHelpers::toInteger);
156    }
157
158    /**
159     * Set the target Android SDK version to compile the server for.
160     * By default, the version from the app build.gradle is used.
161     *
162     * @param apiLevel E.g. 28.
163     * @return self instance for chaining.
164     */
165    public EspressoBuildConfig withTargetSdk(int apiLevel) {
166        return assignToolsVersionsField("targetSdk", apiLevel);
167    }
168
169    /**
170     * Get the target Android SDK version.
171     *
172     * @return Target Android SDK version.
173     */
174    public Optional<Integer> getTargetSdkVersion() {
175        Optional<Object> result = getToolsVersionsFieldValue("targetSdk");
176        return result.map(CapabilityHelpers::toInteger);
177    }
178
179    /**
180     * Kotlin version to compile the server for.
181     * By default, the version from the build.gradle is used.
182     *
183     * @param version E.g. "1.5.10".
184     * @return self instance for chaining.
185     */
186    public EspressoBuildConfig withKotlinVersion(String version) {
187        return assignToolsVersionsField("kotlin", version);
188    }
189
190    /**
191     * Get the target Kotlin version.
192     *
193     * @return Kotlin version.
194     */
195    public Optional<String> getKotlinVersion() {
196        return getToolsVersionsFieldValue("kotlin");
197    }
198
199    /**
200     * Set a non-empty array of dependent module names with their versions.
201     * The scripts add all these items as "implementation" lines of dependencies
202     * category in the app build.gradle script.
203     *
204     * @param dependencies E.g. ["xerces.xercesImpl:2.8.0", "xerces.xmlParserAPIs:2.6.2"].
205     * @return self instance for chaining.
206     */
207    public EspressoBuildConfig withAdditionalAppDependencies(List<String> dependencies) {
208        return assignOptionValue(ADDITIONAL_APP_DEPENDENCIES, dependencies);
209    }
210
211    /**
212     * Get the array of dependent application module names with their versions.
213     *
214     * @return Dependent module names with their versions.
215     */
216    public Optional<List<String>> getAdditionalAppDependencies() {
217        return getOptionValue(ADDITIONAL_APP_DEPENDENCIES);
218    }
219
220    /**
221     * Set a non-empty array of dependent module names with their versions.
222     * The scripts add all these items as "androidTestImplementation" lines of
223     * dependencies category in the app build.gradle script.
224     *
225     * @param dependencies E.g. ["xerces.xercesImpl:2.8.0", "xerces.xmlParserAPIs:2.6.2"].
226     * @return self instance for chaining.
227     */
228    public EspressoBuildConfig withAdditionalAndroidTestDependencies(List<String> dependencies) {
229        return assignOptionValue(ADDITIONAL_ANDROID_TEST_DEPENDENCIES, dependencies);
230    }
231
232    /**
233     * Get the array of dependent Android test module names with their versions.
234     *
235     * @return Dependent module names with their versions.
236     */
237    public Optional<List<String>> getAdditionalAndroidTestDependencies() {
238        return getOptionValue(ADDITIONAL_ANDROID_TEST_DEPENDENCIES);
239    }
240}
241
Full Screen

Accelerate Your Automation Test Cycles With LambdaTest

Leverage LambdaTest’s cloud-based platform to execute your automation tests in parallel and trim down your test execution time significantly. Your first 100 automation testing minutes are on us.

Try LambdaTest
LambdaTestX

We use cookies to give you the best experience. Cookies help to provide a more personalized experience and relevant advertising for you, and web analytics for us. Learn More in our Cookies policy, Privacy & Terms of service

Allow Cookie
Sarah

I hope you find the best code examples for your project.

If you want to accelerate automated browser testing, try LambdaTest. Your first 100 automation testing minutes are FREE.

Sarah Elson (Product & Growth Lead)