Skip to content

Commit c7cd4e5

Browse files
author
Stewart Miles
committed
Fixed Android Resolver when run in a Gradle project.
If a parent directory containing a Unity project also contained a settings.gradle (i.e Gradle project) the Android Resolver would fail with: PlayServicesResolver.scripts.download_artifacts.gradle is not part of the build defined by settings file... This fixes the issue by creating a Gradle project in the temporary directory used by the Android Resolver to run the download_artifacts.gradle script. Fixes #278 Bug: 141749513 Change-Id: Ic6394b7bd0e7a4f9a3ffde33e1390a2a2d437a22
1 parent 24e1aa8 commit c7cd4e5

File tree

7 files changed

+72
-8
lines changed

7 files changed

+72
-8
lines changed

build.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -1027,7 +1027,7 @@ task cleanPackageManagerTests() {
10271027

10281028
task testDownloadArtifacts(type: GradleBuild) {
10291029
description "Run tests for the download_artifacts.gradle script."
1030-
buildFile "source/PlayServicesResolver/scripts/download_artifacts_test.gradle"
1030+
dir "source/PlayServicesResolver/scripts"
10311031
}
10321032

10331033
task testPackageUploader(type: Exec) {

settings.gradle

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/*
2+
* Copyright 2019 Google Inc. All rights reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
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+
17+
rootProject.name = "playServicesResolver"

source/PlayServicesResolver/PlayServicesResolver.csproj

+3
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,9 @@
8787
<EmbeddedResource Include="scripts\download_artifacts.gradle">
8888
<Link>scripts\download_artifacts.gradle</Link>
8989
</EmbeddedResource>
90+
<EmbeddedResource Include="scripts\settings.gradle">
91+
<Link>scripts\settings.gradle</Link>
92+
</EmbeddedResource>
9093
</ItemGroup>
9194
<ItemGroup>
9295
<ProjectReference Include="..\VersionHandler\VersionHandler.csproj">
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/*
2+
* Copyright 2019 Google Inc. All rights reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
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+
17+
apply from: "download_artifacts_test.gradle"

source/PlayServicesResolver/scripts/download_artifacts_test.gradle

+3-2
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,8 @@ project.ext {
7676
outputDir = new File(System.getProperty("user.dir"),
7777
"download_artifacts_test_output")
7878

79-
// Gradle file under test.
79+
// Gradle project under test.
80+
srcSettingsFile = new File(scriptDirectory, "settings.gradle")
8081
srcBuildFile = new File(scriptDirectory, "download_artifacts.gradle")
8182
buildFile = new File(outputDir, srcBuildFile.name)
8283

@@ -123,7 +124,7 @@ task copyTestScript(
123124
type: Copy,
124125
dependsOn: createDirectoryTask(project.ext.outputDir)) {
125126
description "Copy the test script into the test project"
126-
from srcBuildFile
127+
from srcBuildFile, srcSettingsFile
127128
into outputDir
128129
}
129130

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/*
2+
* Copyright 2019 Google Inc. All rights reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
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+
17+
rootProject.name = "androidResolver"
18+

source/PlayServicesResolver/src/GradleResolver.cs

+13-5
Original file line numberDiff line numberDiff line change
@@ -252,11 +252,19 @@ private void GradleResolution(
252252

253253
// Extract the gradle wrapper and build script.
254254
if (!(gradleWrapper.Extract(PlayServicesResolver.logger) &&
255-
EmbeddedResource.ExtractResources(typeof(GradleResolver).Assembly,
256-
new KeyValuePair<string, string>[] {
257-
new KeyValuePair<string, string>(
258-
null, buildScript),
259-
}, PlayServicesResolver.logger))) {
255+
EmbeddedResource.ExtractResources(
256+
typeof(GradleResolver).Assembly,
257+
new KeyValuePair<string, string>[] {
258+
new KeyValuePair<string, string>(null, buildScript),
259+
// Copies the settings.gradle file into this folder to mark it as a Gradle
260+
// project. Without the settings.gradle file, Gradle will search up all
261+
// parent directories for a settings.gradle and prevent execution of the
262+
// download_artifacts.gradle script if a settings.gradle is found.
263+
new KeyValuePair<string, string>(
264+
PlayServicesResolver.EMBEDDED_RESOURCES_NAMESPACE + "settings.gradle",
265+
Path.GetFullPath(Path.Combine(gradleWrapper.BuildDirectory,
266+
"settings.gradle"))),
267+
}, PlayServicesResolver.logger))) {
260268
PlayServicesResolver.Log(String.Format(
261269
"Failed to extract {0} and {1} from assembly {2}",
262270
gradleWrapper.Executable, buildScript,

0 commit comments

Comments
 (0)