Android ExampleApp cannot be opened in Android Studio if it's moved out from the sdk directory tree
bug
**Describe the bug**
The android ExampleApp's [readme](https://github.com/meganz/sdk/blob/master/examples/android/ExampleApp/README.md) says:
> In case you want to copy the example to a different path of your choice, you need to place a copy of the SDK in the folder `<your_path>/ExampleApp/app/src/main/jni/mega` (or you can clone the repository, so you can keep the SDK up to date).
If you do this, then you'll run into an issue with how Android Studio resolves invalid pathes.
The [build.gradle of ExampleApp](https://github.com/meganz/sdk/blob/master/examples/android/ExampleApp/app/build.gradle) contains the following:
```
android {
(...)
sourceSets.main {
java {
srcDirs += '../../../../bindings/java/nz/mega/sdk'
srcDirs += '../../../../../../../../main/java/'
exclude '**/MegaApiSwing.java'
}
jni.srcDirs = [] //disable automatic ndk-build
jniLibs.srcDir 'src/main/libs' // This is not necessary unless you have precompiled libraries in your project.
}
(...)
}
```
Those relative pathes starting with "../../.." work only as long the ExampleApp remains in the sdk repo's directory structure.
If you move the ExampleApp folder somewhere else, things start to behave erratically.
Android Studio doesn't just fail to import the project if it hits a relative path that cannot be resolved properly.
It tries to "make sense" of the path by using the longest prefix of it that still resolves to an existing directory.
Thus if you move ExampleApp e.g. into /home/myuser/src/ExampleApp, then the longest valid prefix of the '../../../../../../../../main/java/' path will be '../../../..', which will point to '/', i.e. the root of the given filesystem. And as a result Android Studio starts to index the root folder recursively!
It'll also give the following warning:
> External file changes sync may be slow.
> Android Studio cannot receive filesystem event notifications for the project. Is it on a network drive?
Meanwhile Android Studio gets seemingly stuck with "Updating indexes ...", but actually it pushes the CPU load to its limits by trying to index the entire filesystem.
**To Reproduce**
Steps to reproduce the behavior:
1. Checkout sdk repo.
2. Move `<sdk>/examples/android/ExampleApp` to e.g. `$HOME/ExampleApp`.
3. Try to open the ExampleApp folder in Android Studio.
**Expected behavior**
Project is imported into Android Studio with a couple of warnings/errors.
The reason for the latter is that we didn't build the sdk yet, thus we don't have the necessary java bindings compiled yet.
**Screenshots**
I don't think this is necessary, since the bug/issue (and a potential fix) is well described. And it's trivially reproducible.
**Environment:**
- SDK Version: v9.16.1
- OS: Ubuntu 22.04.5 LTS
- Android Studio: Narwhal Feature Drop (2025.1.2 Canary 4)
- Device: Android
**Additional context**
No additional context.
0 条评论