【问题标题】:unresolved reference error while generating signed apk in android在android中生成签名apk时未解决的参考错误
【发布时间】:2020-06-02 17:16:43
【问题描述】:

在生成签名的 apk 时,我收到一个名为“未解析的参考:CUSTOM_BASED_URL”的错误。 但是当我尝试生成调试 apk 时没有这种类型的错误

import androidx.databinding.library.BuildConfig
import me.rieshikasharma.india.covid19app.BuildConfig.CUSTOM_BASE_URL
import me.rieshikasharma.india.covid19app.data.retrofit.CustomAppRepository
import okhttp3.OkHttpClient
import okhttp3.logging.HttpLoggingInterceptor
import org.koin.dsl.module
import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory

val networkModule = module {
    single { provideRetrofit() }
    single { CustomAppRepository(get()) }
}

fun provideRetrofit(): Retrofit {
    return Retrofit.Builder().baseUrl(CUSTOM_BASE_URL).client(provideOkHttpClient())
        .addConverterFactory(GsonConverterFactory.create()).build()
}

fun provideOkHttpClient(): OkHttpClient {
    val builder = OkHttpClient()
        .newBuilder()
    if(BuildConfig.DEBUG){
        val requestInterceptor = HttpLoggingInterceptor().setLevel(HttpLoggingInterceptor.Level.BODY)
        builder.addNetworkInterceptor(requestInterceptor)
    }
    return  builder.build()
}

错误已在上面的代码中显示。错误是“未解决的参考:CUSTOM_BASE_URL 请帮我弄清楚! 谢谢

【问题讨论】:

  • 您的CUSTOM_BASE_URL 可能无法在您的release 构建中访问,但在debug 构建中可用。因此,请检查您是否隐藏了您的基本网址。
  • 是的,我已经检查过了!...当此调试 apk 生成时...我的项目结构得到了 chnaged..自动...生成了一个 .idea 文件,我的文件在其中保存(在我定义了基本网址)...我现在应该做什么?
  • 你的网址保存在哪里?

标签: android reference apk signed


【解决方案1】:

所以 url 在名为 buildconfig.java 的文件中

 package me.rieshikasharma.india.covid19app;

public final class BuildConfig {
  public static final boolean DEBUG = Boolean.parseBoolean("true");
  public static final String APPLICATION_ID = "me.rieshikasharma.india.covid19app.debug";
  public static final String BUILD_TYPE = "debug";
  public static final String FLAVOR = "";
  public static final int VERSION_CODE = 1;
  public static final String VERSION_NAME = "1.0";
  // Fields from build type: debug
  public static final String CUSTOM_BASE_URL = "https://api.covid19india.org/";
}

该项目在我的设备中运行良好(在构建 apk 之后)但这里的问题是生成签名的 apk 它显示错误“未解决的参考:custom_base_url” 也请告诉我,在我生成构建 apk 之后,我的整个项目结构发生了变化,也出现了一些新文件。 以及我保存 URL 的文件,整个文件被转移到 gradle 生成的那些文件夹中。

【讨论】:

    猜你喜欢
    • 2023-04-01
    • 2023-04-06
    • 2020-03-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-01-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多