小编jem*_*ili的帖子

如何配置 KMM 项目以支持不同的构建类型

当我切换构建变体时,出现编译错误,但问题仅适用于非默认构建变体(debug & release)。因此,如果我定义customBuild { }然后选择那个,它就会失败并显示以下错误日志:

    The consumer was configured to find a runtime of a component, 
    preferably optimized for Android, as well as attribute 'com.android.build.api.attributes.BuildTypeAttr' 
    with value 'customBuild', attribute 'org.jetbrains.kotlin.platform.type' with value 'androidJvm'.
    However we cannot choose between the following variants of project :shared-module:
- iosArm64RuntimeOnly
          - iosX64RuntimeOnly
        All of them match the consumer attributes:
          - Variant 'iosArm64RuntimeOnly' capability ExampleApp:shared-module:1.0:
              - Unmatched attributes:
                  - Doesn't say anything about com.android.build.api.attributes.BuildTypeAttr (required 'customBuild')
                  - Doesn't say anything about …
Run Code Online (Sandbox Code Playgroud)

android gradle-kotlin-dsl kotlin-multiplatform kotlin-multiplatform-mobile

9
推荐指数
0
解决办法
1509
查看次数

如何在 BottomSheetDialogFragment 顶部显示另一个片段

有什么办法可以在上面显示片段吗DialogFragment?当我BottomSheetDialogFragment在某些操作后显示时,我需要显示另一个片段(不是对话框片段的类型)而不关闭该对话框,我尝试从对话框中删除暗淡效果并隐藏视图,但这不好,对话框片段是不可见,但是,它的顶部是钢制的,按背面键首先会删除这个不可见的对话框,我需要实现的是正常的后堆栈顺序,就像“正常”片段一样

android fragment dialogfragment android-bottomsheetdialog

7
推荐指数
1
解决办法
1712
查看次数

尝试使用 Retrofit @Streaming 注释下载大文件时出现 OutOfMemoryError

我正在使用改造客户端下载文件,但是当存在大文件(200 MB)时它会抛出错误java.lang.OutOfMemoryError:@Streaming也有注释,这是我的下载服务方法

@Streaming
@GET("{path}")
suspend fun downloadFile(@Path("path") path: String): Response<ResponseBody>`
Run Code Online (Sandbox Code Playgroud)

这是调用代码片段

suspend fun downloadFile(remotePath: String): FileDownloadResponse {
  try {
    val response = api.downloadFile(remotePath)
    if (response.isSuccessful) {
       FileDownloadResponse.Success(response.body()!!)
    } else {
      FileDownloadResponse.Fail()
    }
   } catch (e: Exception) {
     e.printStakTrace()
     FileDownloadResponse.Fail(throwable = e)

   }

}

val response = remoteRepositroy.downloadFile(remotePath)
val writeResult = response.body.writeResponseBodyToDisk()
Run Code Online (Sandbox Code Playgroud)

改装版=2.6.0

协程版本=1.3.0-M1

java android kotlin retrofit kotlin-coroutines

6
推荐指数
1
解决办法
704
查看次数

使用消息"此处不允许的方法"改进响应代码405

我正在使用改造,我有一个发布请求

interface NetworkApi {

@Headers("Content-Type: application/json")
@POST("/")
fun startLoginRequest(@Body loginModel : LoginModel) : Call<BaseResponseModel>

class Factory {
    var retrofit = Retrofit.Builder()
            .baseUrl(BASE_URL)
            .addConverterFactory(GsonConverterFactory.create())
            .build()

    companion object{
        fun getApi (): NetworkApi {
            val serverApi = NetworkApi.Factory()
            val api = serverApi.retrofit.create(NetworkApi::class.java)
            return api
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

}

当我使用这个方法并且在响应方法上调用响应体时总是为null.

fun startLoginRequest(){
    val api = NetworkApi.Factory.getApi()
    val request = api.startLoginRequest(loginRequestModel)

    request.enqueue(object : Callback<BaseResponseModel>{
        override fun onFailure(call: Call<BaseResponseModel>?, t: Throwable?) {

        }

        override fun onResponse(call: Call<BaseResponseModel>?, response: Response<BaseResponseModel>?) {
            //here response.body is null
        }
    }) …
Run Code Online (Sandbox Code Playgroud)

android http kotlin retrofit2

5
推荐指数
3
解决办法
6771
查看次数

notifyDataSetChanged() 不调用 onBindViewHolder() 方法

我有一个 RecyclerView 的适配器,我在其中动态添加项目,当我调用适配器的 updateMessages 函数时,旧数据列表正在正确更改,但是回收器项目保持不变。

这是我的适配器中的 updateMessages 方法:

fun updateMessages(messages: List<MessageReceivedResponseModel>?){
    messages?.let {
       this.messages.clear()
       this.messages.addAll(messages)
    }
    notifyDataSetChanged()
}
Run Code Online (Sandbox Code Playgroud)

这里也是完整的适配器类,我不明白有什么问题

class MessagesRecyclerAdapter(private val itemActionListener: IOnMessageItemActionListener) : RecyclerView.Adapter<RecyclerView.ViewHolder>() {

private val messages = ArrayList<MessageReceivedResponseModel>()

override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder {
    val view = LayoutInflater.from(parent.context).inflate(R.layout.awesome_chat_item, parent, false)
    return MyHolder(view)
}

override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {
    (holder as MyHolder).updateUI(messages[position])
}

override fun getItemCount(): Int {
    return messages.size
}

fun updateMessages(messages: List<MessageReceivedResponseModel>?){
    messages?.let {
        this.messages.clear()
        this.messages.addAll(messages)
    }
    notifyDataSetChanged()
}

private inner …
Run Code Online (Sandbox Code Playgroud)

java android listview kotlin android-recyclerview

5
推荐指数
1
解决办法
5365
查看次数

kotlinx.serialization.SerializationException:找不到类“MultiPartFormDataContent”的序列化器

我正在尝试上传多个文件。

val ktorVersion = "1.5.0"
val serializationVersion = "1.0.1"
Run Code Online (Sandbox Code Playgroud)

我就是这样做的:

  override suspend fun uploadFiles(
    binaryFiles: Map<String,ByteArray>
  ): BaseResponse<List<String>> {
    return client.submitForm {

      url(fileUploadUrl)
      method = HttpMethod.Post
      body = MultiPartFormDataContent(
        formData {
          headers{
            append("Content-Type", "application/json")
            append("Authorization", "Bearer $token}")
          }
          binaryFiles.entries.forEach {
            append(
              key = "files",
              value = it.value,
              headers = Headers.build {
                append(HttpHeaders.ContentDisposition, "filename=${it.key}")
              }
            )
          }
        }
      )
    }
  }

Run Code Online (Sandbox Code Playgroud)

但它抛出异常

kotlinx.serialization.SerializationException: Serializer for class 'MultiPartFormDataContent' is not found.
Mark the class as @Serializable or provide the serializer explicitly.
    at …
Run Code Online (Sandbox Code Playgroud)

android ktor kotlinx.serialization ktor-client kotlin-multiplatform-mobile

5
推荐指数
1
解决办法
3698
查看次数