How to use the aws genarated Android SDK with api gateway - android

My deployed AWS API Gateway has one endpoint:
/users with a DELETE Method. I'm trying to call this method from my android app using a generated SDK.
I have deployed the API, then generated the SDK in the API Gateway console and downloaded my zip folder named aws-apigateway-api-sdk-1.0.0. I then ran 'mvn install' inside the folder and copied the generated .jar file and libs into my project and added the gradle imports (basically I did everything as in these instructions until point 7).
Now I want to create the SDK in my android code. In the instructions they do it this way:
// Create an instance of your SDK. Here, 'SimpleCalcClient.java' is the compiled java class for the SDK generated by API Gateway.
final SimpleCalcClient client = factory.build(SimpleCalcClient.class);
My problem is this SimpleCalcClient.class -> I know I need to replace this with my own value, but in my generated target folder I only found following class named LambdaSimpleProxyClient.class, which is an interface. This doesnt seem to be the right class though:
I still tried to use the ApiClientFactory with this class, right now my code looks like this:
public void deleteUser(View view) {
ApiClientFactory factory = new ApiClientFactory();
final LambdaSimpleProxyClient client = factory.build(LambdaSimpleProxyClient.class);
client.usersDelete();
}
The LambdaSimpleProxyClass.java was generated in step 5 when I ran mvn install, it has the method usersDelete() in it, which makes sense to me because that fits with how I called my API Endpoint and looks kinda promising, but I don't rally think that's the class I should use here (but there was no other .class file in my zip folder that was generated by the API Gateway Generate SDK Method:
/**
*
*
* #return Empty
*/
#com.amazonaws.mobileconnectors.apigateway.annotation.Operation(path = "/users", method = "DELETE")
Empty usersDelete();
I also don't understand how to pass my query parameter username in here, but I still tried to call this method. The program then crashes at client.usersDelete();
So what else than LambdaSimpleProxyClient.class should I use there? There is no other .class file in my generated zip folder aws-apigateway-api-sdk-1.0.0 or in my by maven generated target folder.
2020-12-21 20:59:32.427 5340-5340/de.stuttgart.syzl3000 D/ProfileActivity: deleteAccount: delete Btn clicked
2020-12-21 20:59:32.441 5340-5340/de.stuttgart.syzl3000 D/AndroidRuntime: Shutting down VM
2020-12-21 20:59:32.445 5340-5340/de.stuttgart.syzl3000 E/AndroidRuntime: FATAL EXCEPTION: main
Process: de.stuttgart.syzl3000, PID: 5340
java.lang.IllegalStateException: Could not execute method for android:onClick
at androidx.appcompat.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:414)
at android.view.View.performClick(View.java:6256)
at android.view.View$PerformClick.run(View.java:24701)
at android.os.Handler.handleCallback(Handler.java:789)
at android.os.Handler.dispatchMessage(Handler.java:98)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6541)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invoke(Native Method)
at androidx.appcompat.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:409)
at android.view.View.performClick(View.java:6256)
at android.view.View$PerformClick.run(View.java:24701)
at android.os.Handler.handleCallback(Handler.java:789)
at android.os.Handler.dispatchMessage(Handler.java:98)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6541)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
Caused by: com.amazonaws.mobileconnectors.apigateway.ApiClientException: (Service: null; Status Code: 0; Error Code: null; Request ID: null)
at com.amazonaws.mobileconnectors.apigateway.ApiClientHandler.invoke(ApiClientHandler.java:118)
at java.lang.reflect.Proxy.invoke(Proxy.java:913)
at $Proxy1.usersDelete(Unknown Source)
at de.stuttgart.syzl3000.menu.ProfileActivity.deleteAccount(ProfileActivity.java:49)
at java.lang.reflect.Method.invoke(Native Method)
at androidx.appcompat.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:409)
at android.view.View.performClick(View.java:6256)
at android.view.View$PerformClick.run(View.java:24701)
at android.os.Handler.handleCallback(Handler.java:789)
at android.os.Handler.dispatchMessage(Handler.java:98)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6541)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
Caused by: android.os.NetworkOnMainThreadException
at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1448)
at java.net.Inet6AddressImpl.lookupHostByName(Inet6AddressImpl.java:102)
at java.net.Inet6AddressImpl.lookupAllHostAddr(Inet6AddressImpl.java:90)
at java.net.InetAddress.getAllByName(InetAddress.java:787)
at com.android.okhttp.Dns$1.lookup(Dns.java:39)
at com.android.okhttp.internal.http.RouteSelector.resetNextInetSocketAddress(RouteSelector.java:175)
at com.android.okhttp.internal.http.RouteSelector.nextProxy(RouteSelector.java:141)
at com.android.okhttp.internal.http.RouteSelector.next(RouteSelector.java:83)
at com.android.okhttp.internal.http.StreamAllocation.findConnection(StreamAllocation.java:174)
at com.android.okhttp.internal.http.StreamAllocation.findHealthyConnection(StreamAllocation.java:126)
at com.android.okhttp.internal.http.StreamAllocation.newStream(StreamAllocation.java:95)
at com.android.okhttp.internal.http.HttpEngine.connect(HttpEngine.java:281)
at com.android.okhttp.internal.http.HttpEngine.sendRequest(HttpEngine.java:224)
at com.android.okhttp.internal.huc.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:461)
at com.android.okhttp.internal.huc.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:407)
at com.android.okhttp.internal.huc.HttpURLConnectionImpl.getResponseMessage(HttpURLConnectionImpl.java:534)
at com.android.okhttp.internal.huc.DelegatingHttpsURLConnection.getResponseMessage(DelegatingHttpsURLConnection.java:109)
at com.android.okhttp.internal.huc.HttpsURLConnectionImpl.getResponseMessage(Unknown Source:0)
at com.amazonaws.http.UrlHttpClient.createHttpResponse(UrlHttpClient.java:92)
at com.amazonaws.http.UrlHttpClient.execute(UrlHttpClient.java:85)
at com.amazonaws.mobileconnectors.apigateway.ApiClientHandler.invoke(ApiClientHandler.java:109)
at java.lang.reflect.Proxy.invoke(Proxy.java:913)
at $Proxy1.usersDelete(Unknown Source)
at de.stuttgart.syzl3000.menu.ProfileActivity.deleteAccount(ProfileActivity.java:49)
at java.lang.reflect.Method.invoke(Native Method)
at androidx.appcompat.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:409)
at android.view.View.performClick(View.java:6256)
at android.view.View$PerformClick.run(View.java:24701)
at android.os.Handler.handleCallback(Handler.java:789)
at android.os.Handler.dispatchMessage(Handler.java:98)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6541)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
Any hints are welcomed

I had to run the "Generate SDK" in my API Gateway Console again, because somehow the query parameter that I added wasn't in the deployed version. After deploying it again and generating a new SDK, I moved the unzipped folder aws-apigateway-api-sdk-1.0.0 into my app folder. Then the LambdaSimpleProxyClient.class was automatically recognised in the factory.build(LambdaSimpleProxyClient.class) call and I was able to pass the query parameter into the client.deleteUser("<my-username-value>") method that now accepted a passed in String parameter.
There's still an error, but I'll open a new question for that.

Related

How can I get address information using latitude and longitude?

I made this tutorial for get user's address and location but I got error when I changed AVD's location. When I didn't call getCityName function at getLastLocation function, I can get user's location but when I call it, it gave that error. How can I solve it?
it was give an error which was :
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.slidework3, PID: 15792
java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767) 
Caused by: java.io.IOException: grpc failed
at android.location.Geocoder.getFromLocation(Geocoder.java:136)
at com.example.slidework3.AdresPage.getCityName(AdresPage.kt:152)
at com.example.slidework3.AdresPage.access$getCityName(AdresPage.kt:20)
at com.example.slidework3.AdresPage$getLastLocation$1.onComplete(AdresPage.kt:66)
at com.google.android.gms.tasks.zzj.run(Unknown Source:4)
at android.os.Handler.handleCallback(Handler.java:789)
at android.os.Handler.dispatchMessage(Handler.java:98)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6541)
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767) 
Edit:
I tried real device, location services working well I can get city name, street name etc. But in simulator it was give error again. I tried to change AVD's location after that it was going to crash. I believe solution is simple but I don't know how can I search this situation.
Try run the operation in a new Thread, and then if I need to update some UI view I'll do it on runOnUiThread.
https://developer.android.com/training/location/display-address#java

Android app relase - Facebook login button crash

I have a problem with my app where I entered a login button with facebook.
When I use the app and on facebook developer options I have development mode, I have no problems,the app is working properly.
But from the moment I put it in release on facebook developer options, the app crashes as soon as I click on login
I've already put a key release hash on facebook developer, and I've made other attempts, but I can't understand the problem.
java.lang.IllegalStateException: Could not execute method for android:onClick
at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:390)
at android.view.View.performClick(View.java:6663)
at android.view.View.performClickInternal(View.java:6635)
at android.view.View.access$3100(View.java:794)
at android.view.View$PerformClick.run(View.java:26199)
at android.os.Handler.handleCallback(Handler.java:907)
at android.os.Handler.dispatchMessage(Handler.java:105)
at android.os.Looper.loop(Looper.java:216)
at android.app.ActivityThread.main(ActivityThread.java:7625)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:524)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:987)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invoke(Native Method)
at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:385)
at android.view.View.performClick(View.java:6663) 
at android.view.View.performClickInternal(View.java:6635) 
at android.view.View.access$3100(View.java:794) 
at android.view.View$PerformClick.run(View.java:26199) 
at android.os.Handler.handleCallback(Handler.java:907) 
at android.os.Handler.dispatchMessage(Handler.java:105) 
at android.os.Looper.loop(Looper.java:216) 
at android.app.ActivityThread.main(ActivityThread.java:7625) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:524) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:987) 
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'long java.util.Date.getTime()' on a null object reference
at java.util.Calendar.setTime(Calendar.java:1749)
at java.text.SimpleDateFormat.format(SimpleDateFormat.java:984)
at java.text.SimpleDateFormat.format(SimpleDateFormat.java:977)
at java.text.DateFormat.format(DateFormat.java:341)
at com.example.tpistis.tauros.LoginActivity.registra_cliente(LoginActivity.java:270)
at com.example.tpistis.tauros.LoginActivity.apri_app(LoginActivity.java:242)
at java.lang.reflect.Method.invoke(Native Method) 
at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:385) 
at android.view.View.performClick(View.java:6663) 
at android.view.View.performClickInternal(View.java:6635) 
at android.view.View.access$3100(View.java:794) 
at android.view.View$PerformClick.run(View.java:26199) 
at android.os.Handler.handleCallback(Handler.java:907) 
at android.os.Handler.dispatchMessage(Handler.java:105) 
at android.os.Looper.loop(Looper.java:216) 
at android.app.ActivityThread.main(ActivityThread.java:7625) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:524) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:987) 
For those who were looking for an answer, the problem was that on FacebookDevoloper I did not have the privileges to be able to acquire the date of birth, basically you can only acquire name and last name, then the app crashes.

Chuck IncompatibleClassChangeError

I make a simple app, that uses http. For debug previously I used Chuck library. But now, when I try to open http-package from Chuck I get exception and I don't understand why.
You can see the project here: https://github.com/FirstSpectr/Sandbox
Process: ru.spectr.kotlinsandbox, PID: 4699
java.lang.IncompatibleClassChangeError: Class 'com.readystatesoftware.chuck.internal.ui.TransactionActivity' does not implement interface 'androidx.lifecycle.LifecycleOwner' in call to 'androidx.lifecycle.Lifecycle androidx.lifecycle.LifecycleOwner.getLifecycle()' (declaration of 'androidx.lifecycle.LiveData' appears in /data/app/ru.spectr.kotlinsandbox-cFhy1fESF3ecXGlmQrM-Yg==/base.apk!classes2.dex)
at androidx.lifecycle.LiveData.observe(LiveData.java:172)
at androidx.loader.app.LoaderManagerImpl$LoaderInfo.setCallback(LoaderManagerImpl.java:100)
at androidx.loader.app.LoaderManagerImpl.createAndInstallLoader(LoaderManagerImpl.java:400)
at androidx.loader.app.LoaderManagerImpl.initLoader(LoaderManagerImpl.java:421)
at com.readystatesoftware.chuck.internal.ui.TransactionActivity.onCreate(TransactionActivity.java:91)
at android.app.Activity.performCreate(Activity.java:7009)
at android.app.Activity.performCreate(Activity.java:7000)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1214)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2731)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2856)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1589)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6494)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)```
I found problem dependency:
implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0-alpha02'
After deleted chuck work fine

Android : java.lang.NoSuchMethodError: No static method decodeHex

I have added an external library from .jar in my project and whenever I run the the app, it throws this error :
FATAL EXCEPTION: main
Process: com.enginious.snowblossom, PID: 17643
java.lang.NoSuchMethodError: No static method decodeHex(Ljava/lang/String;)[B in class Lorg/apache/commons/codec/binary/Hex; or its super classes (declaration of 'org.apache.commons.codec.binary.Hex' appears in /system/framework/org.apache.http.legacy.boot.jar)
at snowblossom.lib.SnowFieldInfo.(SnowFieldInfo.java:28)
at snowblossom.lib.NetworkParamsTestnet.genSnowFields(NetworkParamsTestnet.java:32)
at snowblossom.lib.NetworkParams.(NetworkParams.java:22)
at snowblossom.lib.NetworkParamsTestnet.(NetworkParamsTestnet.java:13)
at snowblossom.lib.NetworkParams.loadFromConfig(NetworkParams.java:96)
at snowblossom.client.SnowBlossomClient.(SnowBlossomClient.java:281)
at com.enginious.snowblossom.MainActivity.onCreate(MainActivity.java:32)
at android.app.Activity.performCreate(Activity.java:7183)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1220)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2910)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3032)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1696)
at android.os.Handler.dispatchMessage(Handler.java:105)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6944)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374)
org.Appache.Commons is included in the library I have added but it is still throwing this error. I need guidance regarding this issue. Thanks.

RealmIOException: Failed to access: . make_dir() failed

I get this issue when I installed app from MDM(Mobile iron) where application will be wrapped for security purpose.
But it works fine if I install from Android studio,
Can any one please give solution ?
Ream : 1.0.1
minSDK: 18
Stack trace:
Unable to start activity ComponentInfo{forgepond.default.test/com.default.SplashActivity}:
io.realm.exceptions.RealmIOException:
Failed to access: . make_dir() failed: No such file or directory path: /data/user/0/com.default.test/files/default.realm.management
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5794)
at android.app.ActivityThread.-wrap1(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1661)
at android.os.Handler.dispatchMessage(Handler.java:105)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6541)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
Caused by: io.realm.exceptions.RealmIOException: Failed to access: . make_dir() failed: No such file or directory path: /data/user/0/com.default.test/files/default.realm.management
at io.realm.internal.SharedGroup.createNativeWithImplicitTransactions(Native Method)
at io.realm.internal.SharedGroup.openSharedGroupOrFail(SharedGroup.java:95)
at io.realm.internal.SharedGroup.(SharedGroup.java:74)
at io.realm.internal.SharedGroupManager.(SharedGroupManager.java:49)
at io.realm.BaseRealm.(BaseRealm.java:81)
at io.realm.Realm.(Realm.java:139)
at io.realm.Realm.createAndValidate(Realm.java:250)
at io.realm.Realm.createInstance(Realm.java:230)
at io.realm.RealmCache.createRealmOrGetFromCache(RealmCache.java:126)
at io.realm.Realm.getInstance(Realm.java)
As we wrapped using Gen1 wrapper technology which has no external storage access permission is the issue. When we tried with Gen2 wrapper it works fine.

Categories

Resources