Commit 617267bf by ibaker Committed by Oliver Woodman

Fix `core_settings.gradle` to not assume `exoplayerRoot` is absolute

Gradle warns against passing a relative path to `new File(String)`:
https://docs.gradle.org/current/userguide/working_with_files.html#sec:single_file_paths

This change fixes all usages of `exoplayerRoot` to pass it to Gradle's
`Project.file()` first, which returns an absolute `File`.

To reproduce the problem in Issue: #8927:
1. Checkout ExoPlayer git project, to e.g. `~/ExoPlayer/exoplayer-git`
2. Create a new Android Studio project in e.g. `~/AndroidStudioProjects/exoplayer-test`
3. Edit the new project's `settings.gradle` file as described in
   https://github.com/google/ExoPlayer/blob/release-v2/README.md
   using a relative path for `exoplayerRoot`:
   ```
   gradle.ext.exoplayerRoot = '../../ExoPlayer/exoplayer-git'
   ```
4. In a shell:
   ```bash
   $ cd ~/AndroidStudioProjects/exoplayer-test/app
   $ ../gradlew build
   ```

(Step 4 is important, it seems running `./gradlew` from the project root
doesn't trigger the relative path problem)

This change fixes the problem, and also works with `exoplayerRoot` as a
`File` or `Path` object. `String`, `File` and `Path` all work with relative or
absolute paths:
```
gradle.ext.exoplayerRoot = '/home/ibaker/ExoPlayer/exoplayer-git'
gradle.ext.exoplayerRoot = '../../ExoPlayer/exoplayer-git'
gradle.ext.exoplayerRoot = new File('/home/ibaker/ExoPlayer/exoplayer-git')
gradle.ext.exoplayerRoot = new File('../../ExoPlayer/exoplayer-git')
gradle.ext.exoplayerRoot = Paths.get('/home/ibaker/ExoPlayer/exoplayer-git')
gradle.ext.exoplayerRoot = Paths.get('../../ExoPlayer/exoplayer-git')
```

Note: The Path versions above require importing `java.nio.file.Paths`
and changing the `apply from:` line in the project's settings.gradle
file to something like:
```
apply from: file(gradle.ext.exoplayerRoot.resolve('core_settings.gradle'))
```
It's assumed that a project wanting to pass a `Path` will make these
changes.

Issue: #8927
PiperOrigin-RevId: 374421627
parent 941a71ae
...@@ -104,12 +104,12 @@ git checkout release-v2 ...@@ -104,12 +104,12 @@ git checkout release-v2
``` ```
Next, add the following to your project's `settings.gradle` file, replacing Next, add the following to your project's `settings.gradle` file, replacing
`/absolute/path/to/exoplayer` with the absolute path to your local copy: `path/to/exoplayer` with the path to your local copy:
```gradle ```gradle
gradle.ext.exoplayerRoot = '/absolute/path/to/exoplayer' gradle.ext.exoplayerRoot = 'path/to/exoplayer'
gradle.ext.exoplayerModulePrefix = 'exoplayer-' gradle.ext.exoplayerModulePrefix = 'exoplayer-'
apply from: new File(gradle.ext.exoplayerRoot, 'core_settings.gradle') apply from: file("$gradle.ext.exoplayerRoot/core_settings.gradle")
``` ```
You should now see the ExoPlayer modules appear as part of your project. You can You should now see the ExoPlayer modules appear as part of your project. You can
......
...@@ -2,6 +2,10 @@ ...@@ -2,6 +2,10 @@
### 2.14.0 (not yet released) ### 2.14.0 (not yet released)
* Core Library:
* Fix gradle config to allow specifying a relative path for
`exoplayerRoot` when [depending on ExoPlayer locally](README.md#locally)
([#8927](https://github.com/google/ExoPlayer/issues/8927)).
* Extractors: * Extractors:
* Add support for MPEG-H 3D Audio in MP4 extractors * Add support for MPEG-H 3D Audio in MP4 extractors
([#8860](https://github.com/google/ExoPlayer/pull/8860)). ([#8860](https://github.com/google/ExoPlayer/pull/8860)).
......
...@@ -11,10 +11,9 @@ ...@@ -11,10 +11,9 @@
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
def rootDir = gradle.ext.exoplayerRoot def rootDir = file(gradle.ext.exoplayerRoot)
if (!gradle.ext.has('exoplayerSettingsDir')) { if (!gradle.ext.has('exoplayerSettingsDir')) {
gradle.ext.exoplayerSettingsDir = gradle.ext.exoplayerSettingsDir = rootDir.getCanonicalPath()
new File(rootDir.toString()).getCanonicalPath()
} }
def modulePrefix = ':' def modulePrefix = ':'
if (gradle.ext.has('exoplayerModulePrefix')) { if (gradle.ext.has('exoplayerModulePrefix')) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment