[英]How to share Request/Respons class between Android and AWS Lambda
With an Android app that uses AWS Lambda, the Request/Response classes appear in both sides under the different modules of the same project.对于使用 AWS Lambda 的 Android 应用程序,请求/响应类出现在同一项目的不同模块下的两侧。 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
:共享这些类的第一个想法是将lambda
模块添加为app
模块的依赖项,方法是将以下内容添加到app/build.gradle
:
dependencies {
implementation project(":lambda")
But that wouldn't work, since但这行不通,因为
lambda
project depends on the AWK SDK lambda
项目依赖 AWK SDKapp
project depends on AWS Mobile SDK app
项目依赖AWS Mobile SDKand 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.第二种方法是使用符号链接,链接请求/响应类,使它们出现在两个模块中(当然在相同的 package 下),这很有效。 Is it the proper way to do it though?这是正确的方法吗?
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.然后让公共库成为 Android 和 Lambda 代码的依赖项。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.