aws-amplify / aws-sdk-android

AWS SDK for Android. For more information, see our web site:
https://docs.amplify.aws
Other
1.03k stars 551 forks source link

Release versions gives 'Method isn't annotated with Operation' error while making request #710

Closed usmanrana07 closed 2 years ago

usmanrana07 commented 5 years ago

When i make minifyEnabled=true for obfuscation then the app stops working correctly when i try to make request with AWS. I've read this thread as well but it doesn't has solution.

mutablealligator commented 5 years ago

@usmanrana07 Sorry for the delayed response. Our SDK doesn't support obfuscation. We recommend you to configure the proguard rules to keep the classes from the SDK.

You can refer to https://github.com/aws-amplify/aws-sdk-android/blob/master/Proguard.md#modifying-proguard-projecttxt-for-the-aws-sdk-for-android on how to configure Proguard.

usmanrana07 commented 5 years ago

@kvasukib i've already used these rules in my proguard file but that still couldn't resolve the problem.

frankmuellr commented 5 years ago

@usmanrana07 - To help debug your issue further, can you share your build.gradle and proguard.pro files?

usmanrana07 commented 5 years ago

Following are the proguard rules:

# for AWS SDKs

# Class names are needed in reflection
-keepnames class com.amazonaws.**
-keepnames class com.amazon.**
# Request handlers defined in request.handlers
-keep class com.amazonaws.services.**.*Handler
# The following are referenced but aren't required to run
-dontwarn com.fasterxml.jackson.**
-dontwarn org.apache.commons.logging.**
# Android 6.0 release removes support for the Apache HTTP client
-dontwarn org.apache.http.**
# The SDK has several references of Apache HTTP client
-dontwarn com.amazonaws.http.**
-dontwarn com.amazonaws.metrics.**

-dontwarn com.amazonaws.mobile.auth.userpools.ForgotPasswordActivity
-dontwarn com.amazonaws.mobile.auth.userpools.ForgotPasswordView

-keepclassmembers class * {
    @org.greenrobot.eventbus.Subscribe <methods>;
}
-keep enum org.greenrobot.eventbus.ThreadMode { *; }

# Only required if you use AsyncExecutor
#-keepclassmembers class * extends org.greenrobot.eventbus.util.ThrowableFailureEvent {
#    <init>(java.lang.Throwable);
#}

# for Cognito
-keep class com.amazonaws.services.cognitoidentityprovider.** { *; }
-keepclassmembers class ** {
  @com.amazonaws.mobileconnectors.apigateway.annotation.Operation public *;
}

-keepclassmembers class * {
  @proguard.annotation.Keep <methods>;

SDK version:

    // aws
    implementation 'com.amazonaws:aws-android-sdk-apigateway-core:2.13.1'
    //implementation('com.amazonaws:aws-android-sdk-apigateway-core:2.6.+@aar') { transitive = true }
    implementation('com.amazonaws:aws-android-sdk-auth-userpools:2.13.1') { transitive = true }
    implementation('com.amazonaws:aws-android-sdk-cognitoauth:2.13.1') { transitive = true }
foolzoom commented 5 years ago

Do you have any updates on this issue?

I also have this error: com.amazonaws.mobileconnectors.apigateway.ApiClientException: Method isn't annotated with Operation (Service: null; Status Code: 0; Error Code: null; Request ID: null)

My config:

AWS Rules:

# Class names are needed in reflection
 -keepnames class com.amazonaws.**
 -keepnames class com.amazon.**
 # Request handlers defined in request.handlers
 -keep class com.amazonaws.services.**.*Handler
 # The following are referenced but aren't required to run
 -dontwarn com.fasterxml.jackson.**
 -dontwarn org.apache.commons.logging.**
# Android 6.0 release removes support for the Apache HTTP client
-dontwarn org.apache.http.**
# The SDK has several references of Apache HTTP client
-dontwarn com.amazonaws.http.**
-dontwarn com.amazonaws.metrics.**
-dontwarn com.amazonaws.mobile.auth.facebook.FacebookSignInProvider
-dontwarn com.amazonaws.mobile.auth.google.GoogleSignInProvider
-dontwarn com.amazonaws.mobile.auth.userpools.CognitoUserPoolsSignInProvider

-keepclassmembers class ** {
    @com.amazonaws.mobileconnectors.apigateway.annotation.Operation public *;
}
-keepclassmembers class * {
    @com.amazonaws.mobileconnectors.apigateway.annotation.Operation <methods>;
}

SDK Version:

awsMobileClientVer  : "2.7.+@aar",
awsApiGatewayVer    : "2.7.+",
implementation ("com.amazonaws:aws-android-sdk-mobile-client:$libraries.awsMobileClientVer") { transitive = true }
implementation "com.amazonaws:aws-android-sdk-apigateway-core:$libraries.awsApiGatewayVer"
mutablealligator commented 5 years ago

@usmanrana07 I have the following API created in my Android project:

/*
 * Copyright 2010-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License").
 * You may not use this file except in compliance with the License.
 * A copy of the License is located at
 *
 *  http://aws.amazon.com/apache2.0
 *
 * or in the "license" file accompanying this file. This file 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.
 */

package api7e8f4b53;

import java.util.*;

@com.amazonaws.mobileconnectors.apigateway.annotation.Service(endpoint = "https://myapi.execute-api.us-east-2.amazonaws.com/dev")
public interface ApiefbClient {

    /**
     * A generic invoker to invoke any API Gateway endpoint.
     * @param request
     * @return ApiResponse
     */
    com.amazonaws.mobileconnectors.apigateway.ApiResponse execute(com.amazonaws.mobileconnectors.apigateway.ApiRequest request);

    /**
     * 
     * 
     * @return void
     */
    @com.amazonaws.mobileconnectors.apigateway.annotation.Operation(path = "/items", method = "OPTIONS")
    void itemsOptions();

    /**
     * 
     * 
     * @return void
     */
    @com.amazonaws.mobileconnectors.apigateway.annotation.Operation(path = "/items/{proxy+}", method = "OPTIONS")
    void itemsProxyOptions();

}

And I have added the following to proguard rules:

// Keep the annotation
-keepclassmembers class * {
  @proguard.annotation.Keep com.amazonaws.mobileconnectors.apigateway.annotation.Operation;
}

// Keep the methods 
-keepclassmembers class ** {
  @com.amazonaws.mobileconnectors.apigateway.annotation.Operation *;
}

Can you check with these rules in your app?

usmanrana07 commented 5 years ago

It is giving error at following rule line:

Expected field or method name at ~\proguard-rules.pro:97:91 @proguard.annotation.Keep com.amazonaws.mobileconnectors.apigateway.annotation.Operation; ^

usmanrana07 commented 5 years ago

@kvasukib do you have any update or any idea that how long it may take to resolve the issue as my app is on stake due to this issue as i can't obfuscate it.

JSmyth886 commented 5 years ago

Is there any update on this, does version 2.14.0 include any fixes for this issue?

usmanrana07 commented 4 years ago

any update?

YaroslavHavrylovych commented 4 years ago

Please pay attention, that if you're using the "execute" method (not covered with Operation), then you have to keep it as-is (i.e. prevent the method obfuscation with Keep). In the other case, Amazon's handler will fail to detect the method and will give you this error as well.