Reputation: 3177
I am trying to add android-support-v7-appcompat
to my newly created Android project.
Following the Support Library Setup Documentation (developer.android.com/tools/support-library/setup.html), section Adding libraries with resources, I have created an android-support-v7-appcompat project, before adding it as an Android dependency.
EDIT: Here are more details on the process I followed to add the library project as an Android Dependency to the main project:
However, even if the dependency is correctly recognized, Eclipse still sees the compatibility references, such as ActionBarActivity
, as errors, forbidding me to build the project. (See picture here).
To solve this problem, I tried the solutions accepted by similar questions on SE, i.e. adding android-support-v7-appcompat to the Project's Build Path, which successfully silents the errors that prevented me to compile earlier.
However, now when building and deploying the project, I get an error: the app crashes at launch, and the Console displays an error message: Could not find android-support-v7-appcompat.apk!
(See picture here).
To resume, with the first configuration I am not able to compile with Eclipse, while with the second configuration I can't launch the application.
Therefore, I have two questions:
First, how should I be adding a library to my project, so I can at the same time build my project and be able to use the library's additions in my code in Eclipse?
Secondly, I feel like I am missing theoretical knowledge on how Eclipse handles dependencies. What is the difference between adding a library as Android dependency vs Java Dependency / vs adding the project or its jar to the Build path?
Upvotes: 0
Views: 503
Reputation: 1006869
First, how should I be adding a library to my project, so I can at the same time build my project and be able to use the library's additions in my code in Eclipse?
Your first approach should be fine, which would indicate that there is some other problem. For example, there may be errors in the appcompat
library project that are preventing it from being compiled. However, given the error from the second approach, either you are running the appcompat
library (which will not work) or something else is more fundamentally broken in your project setup, where your app thinks that it is supposed to build android-support-v7-appcompat.apk
, when there is no such APK.
What is the difference between adding a library as Android dependency vs Java Dependency / vs adding the project or its jar to the Build path?
Never manually modify the build path in Eclipse for an Android project. While that will satisfy the compiler, the contents of the JAR(s) will not be packaged into your APK for use at runtime, resulting in runtime crashes (e.g., VerifyError
).
"Java dependency" is for pure Java source code. Not only do you not have the source code to appcompat
from the SDK, but an Android library project includes Android resources (and, at least on Android Studio, also assets and an optional manifest file).
For Eclipse, library projects are attached via the approach you describe as the first approach in your question. For Eclipse, plain JARs are just dropped into libs/
in your project root, and those are automatically added to your compile-time and runtime classpaths.
Upvotes: 2