3

In android studio, my unused imports are being immediately removed and I do not want this to happen. I accidentally enabled a recommendation and am not sure how to undo it. Thanx for the assistance.

Wes
  • 53
  • 5
  • 1
    They are unused. Why do you want to keep them? – OneCricketeer Nov 10 '15 at 00:17
  • I've imported a jar file into the libs folder and am now trying to import it into my java code in order to use it, but I'm getting a "symbol not recognized" regarding my package, so I'd like it to not be auto removed while I can try to figure out what's wrong. – Wes Nov 10 '15 at 00:20
  • You'll need to add the jar via the libraries panel. See here http://stackoverflow.com/questions/16608135/android-studio-add-jar-as-library – OneCricketeer Nov 10 '15 at 00:32
  • they will be auto-imported whenever you auto-complete the class name, why would you want to keep those imports? – njzk2 Nov 10 '15 at 02:13
  • @cricket_007 or you can just answer his question. There are many reasons, including, but not limited to... I might need them letter on, while a fix a little problem. Basically, as a developer, I don't want IDE doing stuff I didn't ask it to do. Especially when those things affect my code. – TatiOverflow Feb 10 '17 at 03:18

1 Answers1

2
  1. You can prevent Android Studio from automatically deleting "unused imports" behind your back by turning off "Optimizing Imports":

    Android Studio > File > Settings > Editor General > Auto Import > Optimize imports on the fly = NO

You can read more here: Optimizing Imports

enter image description here

  1. It's perfectly reasonable to want to prevent Android Studio from deleting imports behind your back. When you're done, you can always auto-delete imports with Ctl-Alt-O, or, equivalently, Prject > Optimize Imports.

  2. Finally, how you add 3rd party .jar files depends on your project.

    In my case, I have a "gradle" project, so I need to 1) Add the jar to the "lib" subfolder in my Android Studio project, then 2) edit "dependencies" in your "build.gradle":

How to add a jar in External Libraries in android studio

'Hope that helps!

Community
  • 1
  • 1
paulsm4
  • 114,292
  • 17
  • 138
  • 190
  • Sorry what do you mean by source? I'm not able to find that – Wes Nov 10 '15 at 00:16
  • Actually, I fired up my current Android Studio 1.4: The global setting is now File > Editor > General > Auto Import > Optimize imports on the fly= NO. Apologies for the confusion. You can read more here: [Optimizing Imports](https://www.jetbrains.com/idea/help/optimizing-imports.html) – paulsm4 Nov 10 '15 at 00:22
  • im using 1.4.1 and I can't find editor under file, sorry for the difficulty. I see under tools the option for optimized imports but it's only regarding the action of, not setting it up to do it or not. – Wes Nov 10 '15 at 00:30