我想在cmd上使用gradle重命名包名。由于我有多个项目自定义和使用ide更改包名,很难单独更改每个包名。请给我一个解决办法。提前感谢
apply plugin: 'com.android.application'
apply plugin: 'maven'
android {
compileSdkVersion 21
buildToolsVersion "23.0.0 rc2"
sourceSets {
defaultConfig {
applicationId "com.appbell.restaurant.genericresto"
minSdkVersion 14
targetSdkVersion 19
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
}
main {
manifest.srcFile 'src\main\AndroidManifest.xml'
println('android'+manifest.srcFile)
}
}
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
task changePackage{
replaceInManifest("com.appbell.restaurant.example","com.appbell.imenu4u")
}
buildscript {
repositories {
mavenCentral()
}
dependencies {
// Make sure this is at least 0.10.+
classpath 'com.android.tools.build:gradle:1.0.+'
}
}
task appStart(type: Exec, dependsOn: 'installDebug') {
// linux
//commandLine 'adb', 'shell', 'am', 'start', '-n', 'com.example/.MyActivity'
// windows
commandLine 'cmd', '/c', 'adb', 'shell', 'am', 'start', '-n', 'com.appbell.restaurant.genericresto/com.appbell.and.resto.and.ui.SplashActivity'
}
dependencies {
compile project(':facebook')
compile project(':stripe')
compile 'com.google.android.gms:play-services:+'
compile 'com.android.support:appcompat-v7:21.0.3'
compile files('libs/mobileappclasses.jar')
compile files('libs/pgsdk.jar')
}
def replaceInManifest(fromString, toString) {
def manifestFile = "C:\Users\Ntin Gorle\AndroidstudioProjects\MyApplication\RestoAppNEw\src\main\AndroidManifest.xml"
def updatedContent = new File(manifestFile).getText('UTF-8').replaceAll(fromString, toString)
new File(manifestFile).write(updatedContent, 'UTF-8')
}
如果这个代码包的名称改变了,但没有反映在所有.java文件中。请告诉我如何改变所有的。java类
如果您需要在多个项目中经常更改包名。我推荐"Android Package rename"插件,它在Android Studio插件市场和Intellij IDEA上都有。你所需要做的就是下载并使用它。它适用于许多不同类型的项目。
使用- 点击→文件→重命名包
- 输入要更改的包。
- 单击Ok。
- 同步项目与Gradle文件或无效缓存
你可以在这里看到我的详细答案,或者前往github repo仔细查看说明