I encountered that the method getSearchableInfo
always returns null during SearchView
initialization if I use the packageNameSuffix
in the project's Gradle build script.
SearchView initialization:
final SearchManager searchManager = (SearchManager) context.getSystemService(Context.SEARCH_SERVICE);
SearchableInfo info = searchManager.getSearchableInfo(componentName);
mSearchView.setSearchableInfo(info);
Project's build.gradle:
android {
[...]
buildTypes {
debug {
packageNameSuffix ".debug"
versionNameSuffix "-debug"
signingConfig signingConfigs.debug
}
[...]
}
}
If the package suffix is not used, the given componentName
is ComponentInfo{com.example.android/com.example.android.MapActivity}
and the SearchView
as well as its associated SuggestionsProvider
work fine.
But if packageNameSuffix
is set to ".debug"
, the given componentName
is ComponentInfo{com.example.android.debug/com.example.android.MapActivity}
and the SearchManager
returns null
, instead of returning the respective SearchableInfo
object.
Does anyone know how to get the right SearchableInfo
from the SearchManager
? Thanks!
[EDIT]
Eugen Martinov mentioned in the comments that this behaviur could have to do something with an improper or missing authorities renaming. But i also configured a build type dependent naming of the authorities, that i omitted in the initial post for the sake of simplicity.
Project's build.gradle:
android {
[...]
sourceSets {
debug {
java.srcDirs = [
'src/main/java'
]
java.srcDirs = [
'src/debug/res',
'src/main/res'
]
}
release {
java.srcDirs = [
'src/main/java'
]
java.srcDirs = [
'src/release/res',
'src/main/res'
]
}
[...]
}
}
src/debug/res/values/build-config.xml:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="cfg_app_name">App - Debug</string>
<string name="cfg_authorities">com.example.debug.SuggestionsProvider</string>
<string name="cfg_maps_key"><!-- some key --></string>
</resources>
src/release/res/values/build-config.xml:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="cfg_app_name">App</string>
<string name="cfg_authorities">com.example.SuggestionsProvider</string>
<string name="cfg_maps_key"><!-- some other key --></string>
</resources>
src/main/res/xml/searchable.xml:
<?xml version="1.0" encoding="utf-8"?>
<searchable xmlns:android="http://schemas.android.com/apk/res/android"
android:hint="@string/action_search_hint"
android:label="@string/cfg_app_name"
android:includeInGlobalSearch="false"
android:queryAfterZeroResults="true"
android:searchSuggestAuthority="@string/cfg_authorities"
android:searchSuggestIntentAction="android.intent.action.VIEW"
android:searchSuggestThreshold="3" />
Installing both the debug (with the packageNameSuffix
option) and the release apk on the same device works. I don't get an error like Failure [INSTALL_FAILED_CONFLICTING_PROVIDER]
... But as already said, SearchableInfo
is null
then.
Installing both apk withouth the packageNameSuffix
option leads into the following error: Failure [INSTALL_PARSE_FAILED_INCONSISTENT_CERTIFICATES] - Installation failed since the device already has an application with the same package but a different signature.
Or am i missing something here?
[/EDIT]