Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Studio 3.1.2 loads wrong project

I have migrated my 2.3 settings to 3.1.2, and for testing I have opened a smaller project of mine, "proj2", in Android Studio 3.1.2. Structure of my projects:

AndroidDir/
  proj1/
    app
    lib
  proj2
    app

In proj2, I refer to proj1 lib, an Android library, with proj2/settings.gradle:

include ':lib', ':app'
project(':lib').projectDir = new File(settingsDir, '../proj1/lib')

In 2.3 this worked without any problems, and I could edit my lib code in both proj1 and proj2.

In 3.1.2, proj2 is treated as if I had loaded proj1, while I have opened the proj1 path. Android Studio shows the path of proj2 in the title bar, but the project overview shows all modules of proj1. And it tries to build proj1 instead of proj2. Restarting does not help.

like image 958
Andi Avatar asked May 16 '18 23:05

Andi


2 Answers

Remove the proj2/.idea directory, then, in Android Studio, choose "File -> Invalide Caches / Restart..."

like image 72
Andi Avatar answered Sep 30 '22 06:09

Andi


I am having this problem as well on Android Studio 3.4 and 3.5 canary 13.

More specifically, when I try to share gradle modules between different projects using the .projectDir directive in settings.gradle as described above, any attempt to load a second project that shares that gradle module will fail.

My current workaround is to use Git to load the shared gradle module into a different folder so that each project winds up with its own copy of that shared Gradle module like so:

Project A:

include ':lib', ':app'
project(':lib').projectDir = new File("./path/to/proj1/lib")

Project B:

include ':lib', ':app'
project(':lib').projectDir = new File( "../different/path/to/copy/of/proj1/lib")

Yes, this workaround brings with it its own set of problems like having to constantly sync the 2 folders, so please,

Please upvote this issue here to give it more priority.

like image 43
Phileo99 Avatar answered Sep 30 '22 05:09

Phileo99