如何在Android和AWS Lambda之间共享Request/Response类。

huangapple go评论48阅读模式
英文:

How to share Request/Respons class between Android and AWS Lambda

问题

使用一个使用AWS Lambda的Android应用程序,Request/Response类在同一个项目的不同模块下都出现在两侧。如果不共享,这两个类将出现在2个地方:

.
├── app
│     └── src
│         ├── main
│         │     └── java
│         │          └── com
│         │               └── myapp
│         │                   ├── Request.java
│         │                   └── Response.java
│         └── test
├── lambda
│     └── src
│         └── main
│             └── java
│                 └── com
│                     └── myapp
│                         ├── Request.java
│                         └── Response.java

共享这些类的第一个想法是将lambda模块添加为app模块的依赖项,将以下内容添加到app/build.gradle

dependencies {
    implementation project(":lambda")

但这样做行不通,因为:

  • lambda项目依赖于AWS SDK
  • app项目依赖于AWS移动SDK

它们彼此不兼容(两者在同一包下提供了一些相同的类)。

第二种方法是使用符号链接,将Request/Response类链接起来,以便它们在两个模块中都出现(当然是在相同的包下),这样可以工作。不过这是正确的做法吗?

英文:

With an Android app that uses AWS Lambda, the Request/Response classes appear in both sides under the different modules of the same project. If not shared, the two classes will appear in 2 places:

.
├── app
│   └── src
│       ├── main
│       │   └── java
│       │       └── com
│       │           └── myapp
│       │              ├── Request.java
│       │              └── Response.java
│       └── test
├── lambda
│   └── src
│       └── main
│           └── java
│               └── com
│                   └── myapp
│                      ├── Request.java
│                      └── Response.java

The first idea to share these classes is to add lambda module as a dependency to the app module, by adding the following to app/build.gradle:

dependencies {
    implementation project(":lambda")

But that wouldn't work, since

  • lambda project depends on the AWK SDK
  • app project depends on AWS Mobile SDK

and they are not compatible with each other (both provides some same classes under the same package).

The second method is to use symbolic links, linking the Request/Response classes so that they appear in both modules (under the same package of course), which works. Is it the proper way to do it though?

答案1

得分: 2

我将创建一个第三个区域,专门用于“通用”代码。类似于:

├── app
│   └── src
│       ├── main
│       │   └── java
│       │       └── com
│       │           └── myapp
│       └── test

├── lambda
│   └── src
│       └── main
│           └── java
│               └── com
│                   └── myapp

├── common
│    └── src
│       └── main
│           └── java
│               └── com
│                   └── myapp
│                      ├── Request.java
│                      └── Response.java

然后,将通用库作为Android和Lambda代码的依赖。

英文:

I would create a third area, specifically for "common" code. Something like:

├── app
│   └── src
│       ├── main
│       │   └── java
│       │       └── com
│       │           └── myapp
│       └── test
│
├── lambda
│   └── src
│       └── main
│           └── java
│               └── com
│                   └── myapp
├── common
│    └── src
│       └── main
│           └── java
│               └── com
│                   └── myapp
│                      ├── Request.java
│                      └── Response.java

and then have the common library be a dependency for both the Android and the Lambda code.

huangapple
  • 本文由 发表于 2020年10月9日 21:50:06
  • 转载请务必保留本文链接:https://go.coder-hub.com/64281424.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定