根据你在cmets中写的,假设你有这个:
Picasso.with(context).load("roman-android.com/" + View_stories.files + "/" + stories.images_view).into(holder.img_view);
你需要隐藏roman-android.com/。
你可以这样做:
在您的 Android 项目中打开您的 gradle.properties 文件。这个文件应该是保密的,不能在线获得。
在gradle.properties写下你的链接:
mySecretLink="roman-android.com/"
转到您的build.gradle(module:app) 文件并在android 下添加:
buildTypes.each {
it.buildConfigField "String" , "MY_SECRET_LINK", mySecretLink
}
这样你就会有这样的东西:
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion "25.0.2"
defaultConfig {
//blah blah stuff
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
buildTypes.each {
it.buildConfigField "String" , "MY_SECRET_LINK", mySecretLink
}
}
repositories {
jcenter()
mavenCentral()
}
dependencies {
//blah blah stuff
}
这将告诉 gradle 将您的 String 添加到 BuildConfig 类中,该类在构建时生成并且完全在您的代码之外。
转到您的代码并执行以下操作:
Picasso.with(context).load(BuildConfig.MY_SECRET_LINK + View_stories.files + "/" + stories.images_view).into(holder.img_view);
注意:我已尝试解释 this 并根据您的情况进行调整。我的解释基于我的一个旧代码,我这样做是为了隐藏我的 API 密钥。
显然您需要对gradle.properties 文件保密。您将只在编译时使用它的真实值,在整个编程过程中为您的保密信息(例如MY_SECRET_LINK)保留别名。