Keywords: Android Development | Shared Library Error | Google Maps API
Abstract: This article provides a comprehensive exploration of the common INSTALL_FAILED_MISSING_SHARED_LIBRARY error in Android development, with a focus on scenarios involving Google Maps API. By analyzing error causes, offering detailed resolution steps, and incorporating practical code examples, it helps developers understand shared library dependency mechanisms to prevent installation failures. The content covers key technical aspects such as AVD configuration, project setup, and manifest file modifications, supplemented by additional potential causes.
Error Background and Cause Analysis
During Android application development, when attempting to run an app that depends on specific shared libraries, such as Google Maps API, developers may encounter the INSTALL_FAILED_MISSING_SHARED_LIBRARY error. This error typically indicates that the target device or emulator lacks the required shared library files, causing the installation process to fail. An example error message: [2009-07-11 11:46:43 - FirstMapView] Installation error: INSTALL_FAILED_MISSING_SHARED_LIBRARY, with a prompt to check logcat output for more details.
The root cause lies in the mismatch between the Android app's build target and the runtime environment. For instance, an app using Google Maps API needs to be compiled with the Google APIs build target and run on an Android Virtual Device (AVD) or physical device that supports this API. If the app is built on a standard Android target or run on a device without the necessary shared libraries, this error is triggered.
Core Solution Steps
The key to resolving the INSTALL_FAILED_MISSING_SHARED_LIBRARY error is ensuring consistency across the development environment, project configuration, and runtime environment. The following steps, based on best practices, provide a detailed guide for configuring a Google Maps API application.
Step 1: Install Google APIs
First, ensure that the required Google APIs version is installed in the Android SDK. In Eclipse, this can be done via Windows/Android SDK and AVD Manager -> Available Packages -> Third Party Add-ons -> Google Inc. to find and install Google APIs by Google Inc., Android API X (where X represents the API level). If using Android Studio or command-line tools, similar operations can be performed through the SDK manager.
Step 2: Create an AVD with Google APIs Support
Create a new Android Virtual Device (AVD) and ensure its target is set to Google APIs. This can be done via command line or graphical interface:
- Command-line method: Use
android list targetsto list available targets, then runandroid create avd -n new_avd_api_233 -t "Google Inc.:Google APIs:X"to create the AVD, where-nspecifies the AVD name and-tspecifies the target ID. - Eclipse graphical interface: In
Windows/Android SDK and AVD Manager -> New..., set the name tonew_avd_Xand selectGoogle APIs (Google Inc.) - API Level Xas the target.
Important note: You must select Google APIs as the target; otherwise, the app may still fail due to missing shared libraries.
Step 3: Configure the Android Project
When creating a new Android project in Eclipse, select Google APIs as the build target. Specific operation: File/New/Android Project, and check Google APIs on the build target page. For existing projects, modify the build target in project properties to match Google APIs.
Step 4: Modify AndroidManifest.xml
In the project's AndroidManifest.xml file, add a <uses-library> tag to declare the dependency on the Google Maps shared library. Place the following code inside the <application> tag:
<uses-library android:name="com.google.android.maps" />This tag informs the Android system that the app requires the com.google.android.maps library to function properly. If not declared, the system may fail to load the shared library correctly, leading to installation failure.
Step 5: Run and Test
After completing the above configurations, run the project as an Android application. Ensure to select the previously created Google APIs AVD as the run target. If all configurations are correct, the app should install and launch successfully without the INSTALL_FAILED_MISSING_SHARED_LIBRARY error.
Other Potential Causes and Supplementary Solutions
Beyond Google Maps API, dependencies on other shared libraries can also cause similar errors. For example, if an app incorrectly references a wearable device library but the target device does not support it, the manifest file needs adjustment. Referring to other answers, check and remove unnecessary <uses-library> declarations, such as:
<uses-library android:name="com.google.android.wearable" android:required="true" />If the android:required attribute is set to true but the device lacks the library, installation will fail. Consider changing it to false or dynamically handling dependencies based on device type.
Code Examples and Best Practices
Below is a complete AndroidManifest.xml example demonstrating how to properly configure a Google Maps API application:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.myapp">
<uses-permission android:name="android.permission.INTERNET" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name">
<uses-library android:name="com.google.android.maps" />
<activity
android:name=".MainActivity"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>Best practices include: always confirming target API and shared library dependencies early in development; regularly updating emulator images using the AVD manager; testing on real devices to verify compatibility. By following these steps, developers can effectively avoid the INSTALL_FAILED_MISSING_SHARED_LIBRARY error and enhance development efficiency.