Skip to content

Commit 989a798

Browse files
authored
[Android][Volley] Build fixes (#18899)
* [android] Fix useAndroidMavenGradlePlugin type in template * [android][volley] Use version variables in template * [android][volley] Exclude httpclient As it is incompatible with Android * [android][volley] Resolve file conflict between httpcomponents modules * [android] Update Gradle, the plugins, build tools This fixes building with current Android Studio. Android Gradle plugin version 8.0.0 was chosen for wider compatibility with Android Studio versions (as far back as 2022.2.1). The Maven plugin has been abandoned since the functionality is now built in, and manual jar tasks are not necessary with it. * [android] Regenerate samples
1 parent 6f9ad31 commit 989a798

File tree

24 files changed

+259
-289
lines changed

24 files changed

+259
-289
lines changed

modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AndroidClientCodegen.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -459,8 +459,6 @@ public void processOpts() {
459459
if (additionalProperties.containsKey(USE_ANDROID_MAVEN_GRADLE_PLUGIN)) {
460460
this.setUseAndroidMavenGradlePlugin(Boolean.valueOf((String) additionalProperties
461461
.get(USE_ANDROID_MAVEN_GRADLE_PLUGIN)));
462-
} else {
463-
additionalProperties.put(USE_ANDROID_MAVEN_GRADLE_PLUGIN, useAndroidMavenGradlePlugin);
464462
}
465463

466464
if (additionalProperties.containsKey(ANDROID_GRADLE_VERSION)) {
@@ -483,8 +481,9 @@ public void processOpts() {
483481
this.setSerializableModel(Boolean.valueOf(additionalProperties.get(CodegenConstants.SERIALIZABLE_MODEL).toString()));
484482
}
485483

486-
// need to put back serializableModel (boolean) into additionalProperties as value in additionalProperties is string
484+
// need to put back boolean properties into additionalProperties as the values in additionalProperties are strings
487485
additionalProperties.put(CodegenConstants.SERIALIZABLE_MODEL, serializableModel);
486+
additionalProperties.put(USE_ANDROID_MAVEN_GRADLE_PLUGIN, useAndroidMavenGradlePlugin);
488487

489488
//make api and model doc path available in mustache template
490489
additionalProperties.put("apiDocPath", apiDocPath);
@@ -524,7 +523,7 @@ private void addSupportingFilesForVolley() {
524523
supportingFiles.add(new SupportingFile("git_push.sh.mustache", "", "git_push.sh"));
525524
supportingFiles.add(new SupportingFile("gitignore.mustache", "", ".gitignore"));
526525
supportingFiles.add(new SupportingFile("pom.mustache", "", "pom.xml"));
527-
// supportingFiles.add(new SupportingFile("settings.gradle.mustache", "", "settings.gradle"));
526+
supportingFiles.add(new SupportingFile("settings.gradle.mustache", "", "settings.gradle"));
528527
supportingFiles.add(new SupportingFile("build.mustache", "", "build.gradle"));
529528
supportingFiles.add(new SupportingFile("manifest.mustache", projectFolder, "AndroidManifest.xml"));
530529
supportingFiles.add(new SupportingFile("apiInvoker.mustache",
Lines changed: 33 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,26 @@
1-
{{#useAndroidMavenGradlePlugin}}
2-
group = '{{groupId}}'
3-
project.version = '{{artifactVersion}}'
4-
{{/useAndroidMavenGradlePlugin}}
5-
6-
buildscript {
7-
repositories {
8-
maven { url "https://repo1.maven.org/maven2" }
9-
jcenter()
10-
}
11-
dependencies {
12-
{{#androidGradleVersion}}
13-
classpath 'com.android.tools.build:gradle:{{{.}}}'
14-
{{/androidGradleVersion}}
15-
{{^androidGradleVersion}}
16-
classpath 'com.android.tools.build:gradle:2.3.+'
17-
{{/androidGradleVersion}}
18-
{{#useAndroidMavenGradlePlugin}}
19-
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5'
20-
{{/useAndroidMavenGradlePlugin}}
21-
}
1+
plugins {
2+
{{#androidGradleVersion}}
3+
id 'com.android.library' version '{{{.}}}'
4+
{{/androidGradleVersion}}
5+
{{^androidGradleVersion}}
6+
id 'com.android.library' version '8.0.0'
7+
{{/androidGradleVersion}}
8+
id 'maven-publish'
229
}
2310

24-
allprojects {
25-
repositories {
26-
jcenter()
27-
}
28-
}
29-
30-
31-
apply plugin: 'com.android.library'
32-
{{#useAndroidMavenGradlePlugin}}
33-
apply plugin: 'com.github.dcendents.android-maven'
34-
{{/useAndroidMavenGradlePlugin}}
35-
3611
android {
12+
namespace "{{invokerPackage}}"
3713
{{#androidSdkVersion}}
3814
compileSdkVersion {{{.}}}
3915
{{/androidSdkVersion}}
4016
{{^androidSdkVersion}}
41-
compileSdkVersion 25
17+
compileSdkVersion 33
4218
{{/androidSdkVersion}}
4319
{{#androidBuildToolsVersion}}
4420
buildToolsVersion '{{{.}}}'
4521
{{/androidBuildToolsVersion}}
4622
{{^androidBuildToolsVersion}}
47-
buildToolsVersion '25.0.2'
23+
buildToolsVersion '34.0.0'
4824
{{/androidBuildToolsVersion}}
4925
useLibrary 'org.apache.http.legacy'
5026
defaultConfig {
@@ -53,27 +29,20 @@ android {
5329
targetSdkVersion {{{.}}}
5430
{{/androidSdkVersion}}
5531
{{^androidSdkVersion}}
56-
targetSdkVersion 25
32+
targetSdkVersion 33
5733
{{/androidSdkVersion}}
5834
}
5935
compileOptions {
6036
sourceCompatibility JavaVersion.VERSION_1_8
6137
targetCompatibility JavaVersion.VERSION_1_8
6238
}
63-
64-
// Rename the aar correctly
65-
libraryVariants.all { variant ->
66-
variant.outputs.each { output ->
67-
def outputFile = output.outputFile
68-
if (outputFile != null && outputFile.name.endsWith('.aar')) {
69-
def fileName = "${project.name}-${variant.baseName}-${version}.aar"
70-
output.outputFile = new File(outputFile.parent, fileName)
71-
}
39+
publishing {
40+
singleVariant('release') {
41+
withSourcesJar()
7242
}
7343
}
7444
}
7545

76-
7746
ext {
7847
swagger_annotations_version = "1.6.6"
7948
gson_version = "2.10.1"
@@ -83,38 +52,29 @@ ext {
8352
}
8453

8554
dependencies {
86-
compile "io.swagger:swagger-annotations:$swagger_annotations_version"
87-
compile "com.google.code.gson:gson:$gson_version"
88-
compile "org.apache.httpcomponents:httpcore:$httpcore_version"
89-
compile "org.apache.httpcomponents:httpclient:$httpclient_version"
90-
compile ("org.apache.httpcomponents:httpcore:$httpcore_version") {
55+
implementation "io.swagger:swagger-annotations:$swagger_annotations_version"
56+
implementation "com.google.code.gson:gson:$gson_version"
57+
implementation "org.apache.httpcomponents:httpcore:$httpcore_version"
58+
implementation "org.apache.httpcomponents:httpclient:$httpclient_version"
59+
implementation ("org.apache.httpcomponents:httpcore:$httpcore_version") {
9160
exclude(group: 'org.apache.httpcomponents', module: 'httpclient')
9261
}
93-
compile ("org.apache.httpcomponents:httpmime:$httpclient_version") {
62+
implementation ("org.apache.httpcomponents:httpmime:$httpclient_version") {
9463
exclude(group: 'org.apache.httpcomponents', module: 'httpclient')
9564
}
96-
testCompile "junit:junit:$junit_version"
65+
testImplementation "junit:junit:$junit_version"
9766
}
9867

99-
afterEvaluate {
100-
android.libraryVariants.all { variant ->
101-
def task = project.tasks.create "jar${variant.name.capitalize()}", Jar
102-
task.description = "Create jar artifact for ${variant.name}"
103-
task.dependsOn variant.javaCompile
104-
task.from variant.javaCompile.destinationDirectory
105-
task.destinationDirectory = project.file("${project.buildDir}/outputs/jar")
106-
task.archiveFileName = "${project.name}-${variant.baseName}-${version}.jar"
107-
artifacts.add('archives', task);
108-
}
109-
}
68+
publishing {
69+
publications {
70+
release(MavenPublication) {
71+
groupId = '{{groupId}}'
72+
artifactId = '{{artifactId}}'
73+
version = '{{artifactVersion}}'
11074
111-
{{#useAndroidMavenGradlePlugin}}
112-
task sourcesJar(type: Jar) {
113-
from android.sourceSets.main.java.srcDirs
114-
classifier = 'sources'
115-
}
116-
117-
artifacts {
118-
archives sourcesJar
75+
afterEvaluate {
76+
from components.release
77+
}
78+
}
79+
}
11980
}
120-
{{/useAndroidMavenGradlePlugin}}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-6.7.1-bin.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-all.zip
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists
Lines changed: 52 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,35 @@
1-
{{#useAndroidMavenGradlePlugin}}
2-
group = '{{groupId}}'
3-
project.version = '{{artifactVersion}}'
4-
{{/useAndroidMavenGradlePlugin}}
5-
6-
buildscript {
7-
repositories {
8-
mavenLocal()
9-
google()
10-
maven {
11-
url 'https://dl.google.com/dl/android/maven2'
12-
}
13-
jcenter()
14-
}
15-
dependencies {
16-
classpath 'com.android.tools.build:gradle:3.2.+'
17-
{{#useAndroidMavenGradlePlugin}}
18-
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5'
19-
{{/useAndroidMavenGradlePlugin}}
20-
}
21-
}
22-
23-
allprojects {
24-
repositories {
25-
google()
26-
jcenter()
27-
}
1+
plugins {
2+
{{#androidGradleVersion}}
3+
id 'com.android.library' version '{{{.}}}'
4+
{{/androidGradleVersion}}
5+
{{^androidGradleVersion}}
6+
id 'com.android.library' version '8.0.0'
7+
{{/androidGradleVersion}}
8+
id 'maven-publish'
289
}
2910

30-
31-
apply plugin: 'com.android.library'
32-
{{#useAndroidMavenGradlePlugin}}
33-
apply plugin: 'com.github.dcendents.android-maven'
34-
{{/useAndroidMavenGradlePlugin}}
35-
3611
android {
37-
compileSdkVersion 26
38-
buildToolsVersion '28.0.3'
12+
namespace "{{invokerPackage}}"
13+
{{#androidSdkVersion}}
14+
compileSdkVersion {{{.}}}
15+
{{/androidSdkVersion}}
16+
{{^androidSdkVersion}}
17+
compileSdkVersion 33
18+
{{/androidSdkVersion}}
19+
{{#androidBuildToolsVersion}}
20+
buildToolsVersion '{{{.}}}'
21+
{{/androidBuildToolsVersion}}
22+
{{^androidBuildToolsVersion}}
23+
buildToolsVersion '34.0.0'
24+
{{/androidBuildToolsVersion}}
3925
defaultConfig {
4026
minSdkVersion 14
41-
targetSdkVersion 26
27+
{{#androidSdkVersion}}
28+
targetSdkVersion {{{.}}}
29+
{{/androidSdkVersion}}
30+
{{^androidSdkVersion}}
31+
targetSdkVersion 33
32+
{{/androidSdkVersion}}
4233
}
4334
compileOptions {
4435
sourceCompatibility JavaVersion.VERSION_1_8
@@ -47,24 +38,23 @@ android {
4738
lintOptions {
4839
abortOnError false
4940
}
50-
51-
// Rename the aar correctly
52-
libraryVariants.all { variant ->
53-
variant.outputs.all { output ->
54-
if (outputFile != null && outputFileName.endsWith('.aar')) {
55-
outputFileName = "${archivesBaseName}-${version}.aar"
56-
}
57-
}
41+
packagingOptions {
42+
resources.excludes += "META-INF/DEPENDENCIES"
5843
}
59-
6044
testOptions {
6145
unitTests.returnDefaultValues = true
6246
}
47+
publishing {
48+
singleVariant('release') {
49+
withSourcesJar()
50+
}
51+
}
6352
}
6453

6554
ext {
6655
swagger_annotations_version = "1.6.6"
6756
gson_version = "2.10.1"
57+
httpcore_version = "4.4.16"
6858
httpmime_version = "4.5.14"
6959
volley_version = "1.2.1"
7060
junit_version = "4.13.2"
@@ -75,32 +65,28 @@ ext {
7565
dependencies {
7666
implementation "io.swagger:swagger-annotations:$swagger_annotations_version"
7767
implementation "com.google.code.gson:gson:$gson_version"
78-
implementation "org.apache.httpcomponents:httpmime:$httpmime_version"
68+
implementation ("org.apache.httpcomponents:httpcore:$httpcore_version") {
69+
exclude(group: "org.apache.httpcomponents", module: "httpclient")
70+
}
71+
implementation ("org.apache.httpcomponents:httpmime:$httpmime_version") {
72+
exclude(group: "org.apache.httpcomponents", module: "httpclient")
73+
}
7974
implementation "com.android.volley:volley:${volley_version}"
8075
testImplementation "junit:junit:$junit_version"
8176
testImplementation "org.robolectric:robolectric:${robolectric_version}"
8277
testImplementation "net.jodah:concurrentunit:${concurrent_unit_version}"
8378
}
8479

85-
afterEvaluate {
86-
android.libraryVariants.all { variant ->
87-
def task = project.tasks.create "jar${variant.name.capitalize()}", Jar
88-
task.description = "Create jar artifact for ${variant.name}"
89-
task.dependsOn variant.javaCompile
90-
task.from variant.javaCompile.destinationDirectory
91-
task.destinationDirectory = project.file("${project.buildDir}/outputs/jar")
92-
task.archiveFileName = "${project.name}-${variant.baseName}-${version}.jar"
93-
artifacts.add('archives', task);
94-
}
95-
}
96-
97-
{{#useAndroidMavenGradlePlugin}}
98-
task sourcesJar(type: Jar) {
99-
from android.sourceSets.main.java.srcDirs
100-
classifier = 'sources'
101-
}
80+
publishing {
81+
publications {
82+
release(MavenPublication) {
83+
groupId = '{{groupId}}'
84+
artifactId = '{{artifactId}}'
85+
version = '{{artifactVersion}}'
10286
103-
artifacts {
104-
archives sourcesJar
87+
afterEvaluate {
88+
from components.release
89+
}
90+
}
91+
}
10592
}
106-
{{/useAndroidMavenGradlePlugin}}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,17 @@
1+
pluginManagement {
2+
repositories {
3+
gradlePluginPortal()
4+
google()
5+
mavenCentral()
6+
}
7+
}
8+
9+
dependencyResolutionManagement {
10+
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
11+
repositories {
12+
google()
13+
mavenCentral()
14+
}
15+
}
16+
117
rootProject.name = "{{artifactId}}"
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
6.0.0-SNAPSHOT
1+
7.7.0-SNAPSHOT

samples/client/petstore/android/httpclient/README.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -117,13 +117,6 @@ Class | Method | HTTP request | Description
117117
## Documentation for Authorization
118118

119119
Authentication schemes defined for the API:
120-
### api_key
121-
122-
- **Type**: API key
123-
124-
- **API key parameter name**: api_key
125-
- **Location**: HTTP header
126-
127120
### petstore_auth
128121

129122

@@ -134,6 +127,13 @@ Authentication schemes defined for the API:
134127
- write:pets: modify pets in your account
135128
- read:pets: read your pets
136129

130+
### api_key
131+
132+
- **Type**: API key
133+
134+
- **API key parameter name**: api_key
135+
- **Location**: HTTP header
136+
137137

138138
## Recommendation
139139

0 commit comments

Comments
 (0)