Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot use relative path for exoplayerRoot #9403

Closed
goffioul opened this issue Sep 8, 2021 · 4 comments
Closed

Cannot use relative path for exoplayerRoot #9403

goffioul opened this issue Sep 8, 2021 · 4 comments
Assignees
Labels

Comments

@goffioul
Copy link
Contributor

goffioul commented Sep 8, 2021

I'm using ExoPlayer 2.15.0 as local dependency, with gradle 7.1.1. My settings.gradle contains the following:

gradle.ext.exoplayerRoot = "apps/VideoPlayer/exoplayer/exoplayer-src"
gradle.ext.exoplayerModulePrefix = "exoplayer-"
apply from: file("$gradle.ext.exoplayerRoot/core_settings.gradle")

This leads to build error due to missing dependencies. It turns out that the projectDir of the ExoPlayer modules do not have the expected path. E.g., I added this debug line in settings.gradle:

println(project(':exoplayer-library-core').projectDir)

which prints

/path/to/apps/VideoPlayer/exoplayer/exoplayer-src/apps/VideoPlayer/exoplayer/exoplayer-src/library/core

Note the duplicate parts in the path. AFAICS, this comes from this line in core_settings.gradle:

def rootDir = file(gradle.ext.exoplayerRoot)

If I'm reading gradle docs right, the file method resolves the relative path against the current project, not the top-level one. As the current project is already located at exoplayerRoot, you end up with twice that part in the generated path.

@icbaker
Copy link
Collaborator

icbaker commented Sep 8, 2021

At first glance this looks similar to #8927 which I thought I fixed in 73f28d4 (and was cherry-picked into 2.14.1).

@goffioul
Copy link
Contributor Author

goffioul commented Sep 8, 2021

Something's odd indeed. The same setup in settings.gradle with ExoPlayer 2.11 used to be fine.

@icbaker
Copy link
Collaborator

icbaker commented Sep 8, 2021

Thanks for the report, I reproduced the problem as follows:

  1. Create a new Android Studio project located at /path/to/outer/project.
  2. cd /path/to/outer/project && git clone https://github.com/google/ExoPlayer.git (so now ExoPlayer is rooted at /path/to/outer/project/ExoPlayer)
  3. Modify /path/to/outer/project/settings.gradle:
    gradle.ext.exoplayerRoot = 'ExoPlayer'
    gradle.ext.exoplayerModulePrefix = 'exoplayer-'
    apply from: file("$gradle.ext.exoplayerRoot/core_settings.gradle")
    

AFAICS, this comes from this line in core_settings.gradle:

def rootDir = file(gradle.ext.exoplayerRoot)

If I'm reading gradle docs right, the file method resolves the relative path against the current project, not the top-level one. As the current project is already located at exoplayerRoot, you end up with twice that part in the generated path.

Yep, I agree this is the root of the problem (and I think things were broken by my attempt to fix this that I referenced above). Since the full path to that file is /path/to/outer/project/ExoPlayer/core_settings.gradle and gradle.ext.exoplayerRoot is ExoPlayer then rootDir ends up being /path/to/outer/project/ExoPlayer/ExoPlayer and everything goes wrong from there.

I changed that line to (no arg and empty string aren't allowed):

def rootDir = file(".")

And it seemed to fix the problem. I'll send that change for review - please also give it a try locally and let me know if it works for you (or if it's obviously not sensible - it seems a bit easy!).

@goffioul
Copy link
Contributor Author

goffioul commented Sep 8, 2021

For the record, I also have the impression that the unexpected behavior may come from the fact that the gradle plugin is applied during execution of settings.gradle, and not a regular build.gradle. The context in which the file method is executed might not be what one expect.

icbaker added a commit that referenced this issue Sep 8, 2021
I think this has been broken since 617267b (which was trying to fix
the same problem).

This change initializes `rootDir` to always be the current project (i.e. ExoPlayer)
directory. From the [Gradle docs](https://docs.gradle.org/current/userguide/working_with_files.html#sec:single_file_paths):
> What happens in the case of multi-project builds? The file() method
> will always turn relative paths into paths that are relative to the
> current project directory, which may be a child project.

We can also then remove exoplayerRoot completely and simplify the local
dependency instructions.

* #minor-release
* #exofixit
* Issue: #9403

PiperOrigin-RevId: 395478121
@icbaker icbaker closed this as completed Sep 8, 2021
christosts pushed a commit that referenced this issue Sep 21, 2021
I think this has been broken since 617267b (which was trying to fix
the same problem).

This change initializes `rootDir` to always be the current project (i.e. ExoPlayer)
directory. From the [Gradle docs](https://docs.gradle.org/current/userguide/working_with_files.html#sec:single_file_paths):
> What happens in the case of multi-project builds? The file() method
> will always turn relative paths into paths that are relative to the
> current project directory, which may be a child project.

We can also then remove exoplayerRoot completely and simplify the local
dependency instructions.

* #minor-release
* #exofixit
* Issue: #9403

PiperOrigin-RevId: 395478121
@google google locked and limited conversation to collaborators Nov 8, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants