Support
Quality
Security
License
Reuse
kandi has reviewed DeepLinkDispatch and discovered the below as its top functions. This is intended to give you an instant insight into DeepLinkDispatch implemented functionality, and help decide if they suit your requirements.
A simple, annotation-based library for making deep link handling better on Android
Example
@DeepLink("example://example.com/deepLink/{id}")
public class SampleActivity extends Activity {
@Override protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Intent intent = getIntent();
if (intent.getBooleanExtra(DeepLink.IS_DEEP_LINK, false)) {
Bundle parameters = intent.getExtras();
String idString = parameters.getString("id");
// Do something with idString
}
}
}
Multiple Deep Links
@DeepLink({"foo://example.com/deepLink/{id}", "foo://example.com/anotherDeepLink"})
public class MainActivity extends Activity {
@Override protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Intent intent = getIntent();
if (intent.getBooleanExtra(DeepLink.IS_DEEP_LINK, false)) {
Bundle parameters = intent.getExtras();
String idString = parameters.getString("id");
// Do something with idString
}
}
}
DeepLinkHandler Annotations
@DeepLink("foo://example.com/handlerDeepLink/{param1}?query1={queryParameter}")
object ProjectDeepLinkHandler : DeepLinkHandler<ProjectDeepLinkHandlerArgs>() {
override fun handleDeepLink(parameters: ProjectDeepLinkHandlerArgs) {
/**
* From here any internal/3rd party navigation framework can be called the provided args.
*/
}
}
data class ProjectDeepLinkHandlerArgs(
@DeeplinkParam("param1", DeepLinkParamType.Path) val number: Int,
@DeeplinkParam("query1", DeepLinkParamType.Query) val flag: Boolean?,
)
Method Annotations
@DeepLink("foo://example.com/methodDeepLink/{param1}")
public static Intent intentForDeepLinkMethod(Context context) {
return new Intent(context, MainActivity.class)
.setAction(ACTION_DEEP_LINK_METHOD);
}
Query Parameters
@DeepLink("foo://example.com/deepLink")
public class MainActivity extends Activity {
@Override protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Intent intent = getIntent();
if (intent.getBooleanExtra(DeepLink.IS_DEEP_LINK, false)) {
Bundle parameters = intent.getExtras();
if (parameters != null && parameters.getString("qp") != null) {
String queryParameter = parameters.getString("qp");
// Do something with the query parameter...
}
}
}
}
Configurable path segment placeholders
@DeepLink("foo://cereal.com/<type_of_cereal>/nutritional_info")
public static Intent intentForNutritionalDeepLinkMethod(Context context) {
return new Intent(context, MainActivity.class)
.setAction(ACTION_DEEP_LINK_METHOD);
}
Callbacks
public class DeepLinkReceiver extends BroadcastReceiver {
private static final String TAG = "DeepLinkReceiver";
@Override public void onReceive(Context context, Intent intent) {
String deepLinkUri = intent.getStringExtra(DeepLinkHandler.EXTRA_URI);
if (intent.getBooleanExtra(DeepLinkHandler.EXTRA_SUCCESSFUL, false)) {
Log.i(TAG, "Success deep linking: " + deepLinkUri);
} else {
String errorMessage = intent.getStringExtra(DeepLinkHandler.EXTRA_ERROR_MESSAGE);
Log.e(TAG, "Error deep linking: " + deepLinkUri + " with error message +" + errorMessage);
}
}
}
public class YourApplication extends Application {
@Override public void onCreate() {
super.onCreate();
IntentFilter intentFilter = new IntentFilter(DeepLinkHandler.ACTION);
LocalBroadcastManager.getInstance(this).registerReceiver(new DeepLinkReceiver(), intentFilter);
}
}
Custom Annotations
// Prefix all app deep link URIs with "app://airbnb"
@DeepLinkSpec(prefix = { "app://airbnb" })
// When using tools like Dexguard we require these annotations to still be inside the .dex files
// produced by D8 but because of this bug https://issuetracker.google.com/issues/168524920 they
// are not so we need to mark them as RetentionPolicy.RUNTIME.
@Retention(RetentionPolicy.RUNTIME)
public @interface AppDeepLink {
String[] value();
}
Usage
dependencies {
implementation 'com.airbnb:deeplinkdispatch:x.x.x'
}
KSP
buildscript {
apply from: rootProject.file("dependencies.gradle")
repositories {
google()
gradlePluginPortal()
}
dependencies {
classpath "com.google.devtools.ksp:com.google.devtools.ksp.gradle.plugin:<ksp-version>"
}
}
Kapt
plugins {
id("kotlin-kapt")
}
Java annotation processor
dependencies {
implementation 'com.airbnb:deeplinkdispatch:x.x.x'
annotationProcessor 'com.airbnb:deeplinkdispatch-processor:x.x.x'
}
Incremental annotation processing
javaCompileOptions {
annotationProcessorOptions {
arguments = [
'deepLink.incremental': 'true',
'deepLink.customAnnotations': 'com.airbnb.AppDeepLink|com.airbnb.WebDeepLink'
]
}
}
Performance
Started running tests
benchmark: 11,716 ns DeeplinkBenchmarks.match1
benchmark: 139,375 ns DeeplinkBenchmarks.match500
benchmark: 2,163,907 ns DeeplinkBenchmarks.newRegistry
benchmark: 23,035 ns DeeplinkBenchmarks.match1000
benchmark: 152,969 ns DeeplinkBenchmarks.match1500
benchmark: 278,906 ns DeeplinkBenchmarks.match2000
benchmark: 162,604 ns DeeplinkBenchmarks.createResultDeeplink1
benchmark: 11,774 ns DeeplinkBenchmarks.parseDeeplinkUrl
Tests ran to completion.
Generated deep links Documentation
tasks.withType(JavaCompile) {
options.compilerArgs << "-AdeepLinkDoc.output=${buildDir}/doc/deeplinks.txt"
}
Proguard/R8 Rules
-keep @interface your.package.path.deeplink.<annotation class name>
-keepclasseswithmembers class * {
@your.package.path.deeplink.<annotation class name> <methods>;
}
License
Copyright 2015-2020 Airbnb, Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
API is not working when ProGuard is activated in my Android app
-ignorewarnings
-keep class * {
public private *;
}
-keep class com.google.android.gms.** { *; }
-dontwarn com.google.android.gms.**
-dontwarn org.xmlpull.v1.**
-dontnote org.xmlpull.v1.**
-keep class org.xmlpull.** { *; }
#retRofit
# Platform calls Class.forName on types which do not exist on Android to determine platform.
-dontnote retrofit2.Platform
# Platform used when running on RoboVM on iOS. Will not be used at runtime.
-dontnote retrofit2.Platform$IOS$MainThreadExecutor
# Platform used when running on Java 8 VMs. Will not be used at runtime.
-dontwarn retrofit2.Platform$Java8
# Retain generic type information for use by reflection by converters and adapters.
-keepattributes Signature
# Retain declared checked exceptions for use by a Proxy instance.
-keepattributes Exceptions
-keepclasseswithmembers class * {
@retrofit2.http.* <methods>;
}
# Orm
-keep class * extends com.raizlabs.android.dbflow.config.DatabaseHolder { *; }
# Fresco
-keep,allowobfuscation @interface com.facebook.common.internal.DoNotStrip
-keep @com.facebook.common.internal.DoNotStrip class *
-keepclassmembers class * {
@com.facebook.common.internal.DoNotStrip *;
}
-keepclassmembers class * {
native <methods>;
}
-dontwarn okio.**
-dontwarn com.squareup.okhttp.**
-dontwarn okhttp3.**
-dontwarn javax.annotation.**
-dontwarn com.android.volley.toolbox.**
# com.github.siyamed:android-shape-imageview
-dontwarn android.support.v7.**
-keepattributes *Annotation,Signature
-dontwarn com.github.siyamed.**
-keep class com.github.siyamed.shapeimageview.**{ *; }
-dontwarn org.xmlpull.v1.**
-dontwarn uk.co.senab.photoview.**
#Image Cropper
-keep class androidx.appcompat.widget.** { *; }
# Keep source file names, line numbers, and Parse class/method names for easier debugging
-keepattributes SourceFile,LineNumberTable
-keepnames class com.parse.** { *; }
# Required for Parse
-keepattributes *Annotation*
-keepattributes Signature
-dontwarn com.squareup.**
-dontwarn okio.**
-keepattributes SourceFile,LineNumberTable
-keep class com.parse.*{ *; }
-dontwarn com.parse.**
-dontwarn com.squareup.picasso.**
-keepclasseswithmembernames class * {
native <methods>;
}
```
QUESTION
API is not working when ProGuard is activated in my Android app
Asked 2020-Dec-11 at 09:18After enabling minifyEnabled=true
API is not sending data to server. When I checked in the server, I am getting all the inputs are null. However, if I add -dontobfuscate
in "proguard-rules.pro" file then the app is working fine. I am using retrofit2. I tried almost all the ProGuard rules regarding the retrofit2. Nothing worked!.
My build.gradle
file:
def lifecycleExtensionVersion = '2.2.0'
def butterknifeVersion = '10.1.0'
def supportVersion = '29.0.0'
def retrofitVersion = '2.3.0'
def glideVersion = '4.9.0'
def rxJavaVersion = '2.1.1'
def daggerVersion = '2.14.1'
def mockitoVersion = '2.11.0'
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'com.google.firebase:firebase-crashlytics:17.2.1'
implementation 'com.google.firebase:firebase-messaging:20.2.4'
implementation 'com.google.firebase:firebase-analytics:17.5.0'
implementation 'com.google.firebase:firebase-auth:19.3.0'
implementation "com.android.support:design:$supportVersion"
implementation "android.arch.lifecycle:extensions:$lifecycleExtensionVersion"
implementation "com.jakewharton:butterknife:$butterknifeVersion"
implementation 'androidx.work:work-runtime:2.2.0'
annotationProcessor "com.jakewharton:butterknife-compiler:$butterknifeVersion"
implementation "com.squareup.retrofit2:retrofit:$retrofitVersion"
implementation "com.squareup.retrofit2:converter-gson:$retrofitVersion"
implementation "com.squareup.retrofit2:adapter-rxjava2:$retrofitVersion"
implementation "io.reactivex.rxjava2:rxjava:$rxJavaVersion"
implementation "io.reactivex.rxjava2:rxandroid:$rxJavaVersion"
implementation "com.github.bumptech.glide:glide:$glideVersion"
implementation "com.google.dagger:dagger:$daggerVersion"
implementation "com.google.dagger:dagger-android-support:$daggerVersion"
implementation "androidx.legacy:legacy-support-v4:1.0.0"
annotationProcessor "com.google.dagger:dagger-compiler:$daggerVersion"
annotationProcessor "com.google.dagger:dagger-android-processor:$daggerVersion"
implementation 'com.airbnb:deeplinkdispatch:4.1.0'
annotationProcessor 'com.airbnb:deeplinkdispatch-processor:4.1.0'
testImplementation "org.mockito:mockito-inline:$mockitoVersion"
testImplementation "android.arch.core:core-testing:1.1.1"
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
}
Also, when minifyEnabled=true
, the following "getLoginResult" function is not reaching when I debug. But when I add -dontobfuscate
then it reaches.
LoginViewModel.Java
import android.util.Log;
import androidx.lifecycle.LiveData;
import androidx.lifecycle.MutableLiveData;
import androidx.lifecycle.ViewModel;
import io.reactivex.disposables.CompositeDisposable;
import okhttp3.ResponseBody;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
public class LoginViewModel extends ViewModel {
public MutableLiveData<LoginUser> loginUser = new MutableLiveData<>();
public MutableLiveData<Boolean> loginUserLoadError = new MutableLiveData<>();
public MutableLiveData<Boolean> loading = new MutableLiveData<>();
private CompositeDisposable disposable = new CompositeDisposable();
public LiveData<ResponseBody> getLoginResult(String getEmail, String getPassword, String device_ip){
loading.setValue(true);
final MutableLiveData<ResponseBody> outputReponse = new MutableLiveData<>();
LoginUser loginUser = new LoginUser(getEmail, getPassword, device_ip);
Call<ResponseBody> call = LoginService
.getInstance()
.getLoginAPI()
.loginUser(loginUser);
call.enqueue(new Callback<ResponseBody>() {
@Override
public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
outputReponse.setValue(response.body());
}
@Override
public void onFailure(Call<ResponseBody> call, Throwable t) {
Log.d("Login Failed", t.getLocalizedMessage());
}
});
return outputReponse;
}
What I am missing or doing wrong here? How can I get it work.
ANSWER
Answered 2020-Dec-11 at 09:18Two way you can fix this:
Insert Annotation Keep
for all response and request DTO Class.
Fix to keep all class do you need in proguard-rules.pro
file like this :
-ignorewarnings
-keep class * {
public private *;
}
-keep class com.google.android.gms.** { *; }
-dontwarn com.google.android.gms.**
-dontwarn org.xmlpull.v1.**
-dontnote org.xmlpull.v1.**
-keep class org.xmlpull.** { *; }
#retRofit
# Platform calls Class.forName on types which do not exist on Android to determine platform.
-dontnote retrofit2.Platform
# Platform used when running on RoboVM on iOS. Will not be used at runtime.
-dontnote retrofit2.Platform$IOS$MainThreadExecutor
# Platform used when running on Java 8 VMs. Will not be used at runtime.
-dontwarn retrofit2.Platform$Java8
# Retain generic type information for use by reflection by converters and adapters.
-keepattributes Signature
# Retain declared checked exceptions for use by a Proxy instance.
-keepattributes Exceptions
-keepclasseswithmembers class * {
@retrofit2.http.* <methods>;
}
# Orm
-keep class * extends com.raizlabs.android.dbflow.config.DatabaseHolder { *; }
# Fresco
-keep,allowobfuscation @interface com.facebook.common.internal.DoNotStrip
-keep @com.facebook.common.internal.DoNotStrip class *
-keepclassmembers class * {
@com.facebook.common.internal.DoNotStrip *;
}
-keepclassmembers class * {
native <methods>;
}
-dontwarn okio.**
-dontwarn com.squareup.okhttp.**
-dontwarn okhttp3.**
-dontwarn javax.annotation.**
-dontwarn com.android.volley.toolbox.**
# com.github.siyamed:android-shape-imageview
-dontwarn android.support.v7.**
-keepattributes *Annotation,Signature
-dontwarn com.github.siyamed.**
-keep class com.github.siyamed.shapeimageview.**{ *; }
-dontwarn org.xmlpull.v1.**
-dontwarn uk.co.senab.photoview.**
#Image Cropper
-keep class androidx.appcompat.widget.** { *; }
# Keep source file names, line numbers, and Parse class/method names for easier debugging
-keepattributes SourceFile,LineNumberTable
-keepnames class com.parse.** { *; }
# Required for Parse
-keepattributes *Annotation*
-keepattributes Signature
-dontwarn com.squareup.**
-dontwarn okio.**
-keepattributes SourceFile,LineNumberTable
-keep class com.parse.*{ *; }
-dontwarn com.parse.**
-dontwarn com.squareup.picasso.**
-keepclasseswithmembernames class * {
native <methods>;
}
```
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
No vulnerabilities reported
Save this library and start creating your kit
Explore Related Topics
Save this library and start creating your kit