0

What I wanted to do was simply this: Generate a Debug APK without having it launch emulators and perform downloads. (No, the "compile" and/or "build" is not creating a new debug APK... but that's for another post). After searching, I came across this: Build unsigned APK file with Android Studio

So I followed the steps. Initially my "Gradle Projects" pane was completely empty... but it was building the project just fine. So logically, I have to assume that having an empty "Gradle Projects" pane is the norm.

After performing those steps in the above link, I was now getting 48 (!!) different APK files, where I used to get 6, with such names as "X86-arm-armabi-7a"... (Really? these apks were mixing X86 with arm code?? (my project does have a few native libs in it))

So, to revert back, I simply go in opposite direction. I went back to the gradle pane, and pressed (-) to remove what I added. Yup... one click.

Opps.

Now, it's gone. All the files are still there. But there is no "project" anymore. I open Android Studio, and the project pane is empty. The "Reopen" menu doesn't list it anymore...

In any other environment, simple undoing what you did would take you back to the state you were in before. But not with Android Studio...

All the tutorials I can find are about writing Android apps... nothing about how the underlying architecture of Android Studio actually functions. Other IDEs use make files or solution/ project files like SLN, DSW, QPF, MCP... I can find nothing like that in Android Studio (which would at least give me a restore point from the source repository)

How can I "reconnect" the files back into a "project"? Any trail of clues would be appreciated.

These kinds of fragile things make Android Studio very difficult (and scary) to use...

-CSW

Community
  • 1
  • 1
SpacemanScott
  • 953
  • 9
  • 21
  • 1
    I had a similar problem once. I was trying to remove a library from my project that I no longer needed. In the process of removing the necessary statements from my project gradle file, I accidentally deleted the `apply plugin: 'com.android.applicatoin'` line. Oops, no problem, cntrl+z to the rescue. Nope. Same thing happened to me, all my files "disconnected" even though they were still there. After a day of struggle I finally had to restore from an earlier git commit. All this to say, I sure hope you use version control :( – NoChinDeluxe Feb 11 '16 at 15:43
  • Oh... joy. Yeah, I'm version controlling it, but I hope I hit all the right files. There are literally thousands of generated files in this thing. And without an "Android Studio PhD" you can't know what is easily regenerated, and what is critical. What amazes me is that people think this kind of brittleness is acceptable. – SpacemanScott Feb 11 '16 at 16:09

1 Answers1

0

I was able to restore it. By examining another project, and migrating over the settings from those files. How specifically they work, or if any of these are not necessary, I cannot say.

Here is what I did, with the project name replaced by {name}

In the file /settings.gradle was nothing. So I put back in one single line:

include ':app'

There was a file that appears to be missing: /app/app.iml So I moved it from the other project. Since it has no references to the actual project name, just relative paths and scrip names, I was able to leave it alone.

Next in /{name}.iml there were a bunch of things that were different: (I'm trying to bold the changes, but it's not displaying... so they are called out by asterisks)

<?xml version="1.0" encoding="UTF-8"?>
<module external.linked.project.id="{name}"    external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$" external.system.id="GRADLE" external.system.module.group="" external.system.module.version="unspecified" type="JAVA_MODULE" version="4">
<component name="FacetManager">
    <facet type="java-gradle" name="Java-Gradle">
    <configuration>
        **<option name="BUILD_FOLDER_PATH" value="$MODULE_DIR$/build" />**
        **<option name="BUILDABLE" value="false" />**
  </configuration>
</facet>
</component>
<component name="NewModuleRootManager" inherit-compiler-output="false">
      {deleted two XML tags named 'output'}
<exclude-output />
<content url="file://$MODULE_DIR$">
  <sourceFolder url="file://$MODULE_DIR$/gen" isTestSource="false" generated="true" />
  <excludeFolder url="file://$MODULE_DIR$/.gradle" />
 </content>
 <orderEntry type="jdk" jdkName="Android API 16 Platform" jdkType="Android SDK" />
 <orderEntry type="sourceFolder" forTests="false" />
</component>

Then, down in the hidden folder ".idea", I edited the "gradle.xml" making this one line addition:

<option name="linkedExternalProjectsSettings">
  <GradleProjectSettings>
    <option name="distributionType" value="DEFAULT_WRAPPED" />
    <option name="externalProjectPath" value="$PROJECT_DIR$" />
    <option name="gradleJvm" value="1.8" />
    <option name="modules">
      <set>
        <option value="$PROJECT_DIR$" />
        **<option value="$PROJECT_DIR$/app" />**
      </set>
    </option>
  </GradleProjectSettings>

Next, again in the ".idea" folder, I edited the "modules.xml" to add the applications "iml" file. One line addition:

<modules>
  <module fileurl="file://$PROJECT_DIR$/{name}.iml" filepath="$PROJECT_DIR$/{name}.iml" />
  **<module fileurl="file://$PROJECT_DIR$/app/app.iml" filepath="$PROJECT_DIR$/app/app.iml" />**
</modules>

Then, when I restarted Android Studio, it worked.

Hopefully, the next person who experiences a problem such as I did, will be able to use this to recover.

-CSW

SpacemanScott
  • 953
  • 9
  • 21