英文:
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 SDKapp
项目依赖于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 SDKapp
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论