Keywords: Google Play Services | Android Development | IntelliJ IDEA | Dependency Management | Resource Resolution
Abstract: This technical article addresses the common compilation error 'No resource found that matches the given name' when integrating Google Play Services v4.0. It provides a detailed solution for IntelliJ IDEA users, explaining how to properly configure the google-play-services_lib module as a dependency to resolve resource resolution issues. The article includes step-by-step instructions with GUI screenshots, analyzes the root cause of missing resource values, and discusses the importance of correct module configuration over direct value hardcoding for maintainable Android development.
Introduction to the Problem
With the release of Google Play Services version 4.0 in October 2013, developers were required to add a new meta-data element to their AndroidManifest.xml file. The required configuration appears as follows:
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
However, many developers encountered a compilation error indicating that the resource @integer/google_play_services_version could not be found, despite the resource being present in the google-play-services_lib project at google-play-services_lib/res/values/version.xml with the value 4030500.
Root Cause Analysis
The fundamental issue stems from improper dependency configuration in the development environment. When developers include only the JAR file (google-play-services.jar) rather than the complete library module, they gain access to the compiled code but not the Android resources. This creates a situation where the code compiles successfully because the classes are available, but resource resolution fails because the resource values are not properly included in the project's resource pool.
IntelliJ IDEA Solution
The most effective solution involves correctly configuring the google-play-services_lib as a module dependency rather than a simple library dependency. Begin by accessing the Project Structure dialog through the IDE's menu system. Initially, the project structure may show the google-play-services library in the dependencies list, but this configuration is insufficient for resource resolution.
Remove the existing google-play-services library dependency by selecting it and clicking the minus button. Although this action will generate dependency errors, it's a necessary step in the reconfiguration process. Next, add the google-play-services_lib as a module dependency using the plus button and selecting "Module Dependency." Use the up arrow button to prioritize this dependency at the top of the list, though some dependency errors may persist at this stage.
The critical step involves clicking the lightbulb icon that appears in the error message area. This action presents a popup with two options: "Add to dependencies..." or "Remove Library." Select "Add to dependencies..." to open a new dialog window. This window displays available modules, including your main project and the google-play-services_lib project. Select the google-play-services_lib module and confirm the selection to complete the configuration.
Technical Implementation Details
The correct module dependency configuration ensures that both the compiled code and Android resources from the google-play-services_lib project are properly integrated into your main application. This integration occurs through Android's build system, which merges resources from all dependencies during the compilation process. The resource merging mechanism allows your application to resolve the @integer/google_play_services_version reference to the actual integer value defined in the library's version.xml file.
The version integer itself serves as a compatibility check mechanism. Google Play Services uses this value to verify that the application was built against a compatible version of the library, preventing runtime issues that could occur if the application expects features or APIs that aren't available in the version installed on the user's device.
Alternative Development Environments
For Eclipse users, the solution involves importing the google-play-services_lib folder as an existing Android project and then adding it as a library reference in your project's properties. Navigate to Eclipse's import dialog, select "Existing Android Code Into Workspace," and browse to the google-play-services_lib folder located at android-sdk/extras/google/google_play_services/libproject. After importing, right-click your main project, select Properties, navigate to the Android section, and add the imported google-play-services_lib project to the libraries list.
Code Integration Example
To demonstrate proper integration, consider the following implementation of Google Play Services version checking in an Android activity:
public class MainActivity extends Activity {
private static final int PLAY_SERVICES_RESOLUTION_REQUEST = 9000;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (checkPlayServices()) {
// Initialize Google Play Services components
initializeLocationServices();
}
}
private boolean checkPlayServices() {
int resultCode = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this);
if (resultCode != ConnectionResult.SUCCESS) {
if (GooglePlayServicesUtil.isUserRecoverableError(resultCode)) {
GooglePlayServicesUtil.getErrorDialog(resultCode, this,
PLAY_SERVICES_RESOLUTION_REQUEST).show();
}
return false;
}
return true;
}
}
Best Practices and Maintenance Considerations
Proper dependency management extends beyond simply resolving compilation errors. When working with Google Play Services, always ensure that you're using the latest compatible version and regularly update your dependencies. The module-based approach described in this article provides several advantages over hardcoding the version value, including automatic updates when the library is upgraded, consistent version management across development teams, and reduced maintenance overhead.
Additionally, the correct configuration often resolves secondary issues that may not be immediately apparent. For instance, some developers reported that fixing the dependency configuration also resolved crashes related to GooglePlayServicesUtil.getErrorDialog(...).show() methods, though this could also be attributed to general improvements in the library update.
Conclusion
The missing @integer/google_play_services_version symbol represents a common configuration issue when integrating Google Play Services into Android projects. The solution lies in proper module dependency management rather than workarounds like hardcoding version values. By following the detailed configuration steps for IntelliJ IDEA or the equivalent procedures for Eclipse, developers can ensure robust integration of both code and resources from external libraries, leading to more maintainable and upgradeable Android applications.