To check or not to check “IsLibrary”?

2019-06-25 08:16发布

问题:

I built my app using a library project (that I also created, to be reused in other apps). It builds fine, but when I try to install & run it through Eclipse (Ctrl+F11), I get this red Could not find MyLib.apk! error line in my console:

Console output:

[2013-11-30 14:42:59 - MyApp] ------------------------------
[2013-11-30 14:42:59 - MyApp] Android Launch!
[2013-11-30 14:42:59 - MyApp] adb is running normally.
[2013-11-30 14:42:59 - MyApp] Performing com.sfinja.myapp.ActivitySubClass activity launch
[2013-11-30 14:42:59 - MyApp] Automatic Target Mode: using device '5752068FC64500EA'
[2013-11-30 14:43:00 - MyApp] Application already deployed. No need to reinstall.
[2013-11-30 14:43:00 - MyLib] Could not find MyLib.apk!
[2013-11-30 14:43:00 - MyApp] Starting activity com.sfinja.myapp.ActivitySubClass on device 5752068FC64500EA
[2013-11-30 14:43:00 - MyApp] ActivityManager: Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=com.sfinja.myapp/.ActivitySubClass }

So I searched SO and found this thread which solves the problem by simply unchecking the library project's Is Librarycheckbox.

Sure enough, my Library Project (MyLib) had this checkbox checked so I unchecked it and I no longer receive this error in the console, but then I started getting runtime NullPointerExceptions.

This clearly suggests that I have a problem in my project setup/configuration (although it builds fine) but in order to find what it is, I believe I need to understand a bit more about this confusing checkbox:

  1. I have other library projects used in this app, all having the Is Library checkbox checked but none of them presents the problem exhibited by MyLib. So, to check or not to check "IsLibrary"?
  2. If it is a library, why should the Is Library checkbox be unchecked? Is that thread's correct answer from 2 years ago still valid?
  3. Is the Could not find APK! essentially a "red herring" for something else?

回答1:

I recall encountering a problem similar to yours that drove me nuts. I also thought that unchecking the projects Is Library checkbox would solve the problem but in actuality it didn't.

After lots of lost hours I then found the culprit: An extra, redundant, wicked and totally misleading and destructive line in the project's .classpath:

<classpathentry kind="src" path="/RogueProjLib"/>

(I had no idea how it snuck in)

Once I removed it, the the "Could not find RogueProjLib.apk!" went away and project installed and ran fine, with the Is Library checkbox checked!

Based on that, I would answer your questions as follows:

  1. Your other library projects aren't probably in that .classpath... Yes, do check Is Library.
  2. Question irrelevant because it should be checked. The answer from 2 years ago is no longer relevant with the latest Eclipse/ADT bundle.
  3. Yes, it is a red herring: Instead of telling you "there is a weird line in my .classpath with which I don't know what to do", it just emits that cryptic "Could not find APK" message.

Hope this helps.