how to rename android package name using gradle on cmd? - android

i want to rename package name using gradle on cmd.because i have multiple project customization and change package name using ide very difficult to change each package name separately.please give me solution.thanks in advance
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')
}
I this code package name change but not reflect in all .java file.please tell me how to change in all .java classes.

If you need to change the package name often and in multiple projects. I recommend the plugin "Android Package Renamer", it's available on the Android Studio plugin market and Intellij IDEA. All you need to do is download it and use it. It works well on many different types of projects.
Usage
Open Your Project.
Click -> File -> Rename Package
Input the Package you want to change.
Click Ok.
Sync Project with Gradle Files or Invalidate Caches
You can see my detailed answer here or head over to the github repo for a closer look at the instructions.

Related

Gradle settings for this project are not configured yet - android studio

I'm trying to load an existing project and i'm running into these problems:
clicking ok i will have this:
Searching here I have not found grangle 2.2.2. Minimum grandle is 3.0.0
build.grandle:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.2'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
app.build.grande:
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion '23.0.2'
defaultConfig {
applicationId "com.prouast.heartbeat"
minSdkVersion 15
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
// add a task that calls regular ndk-build(.cmd) script from app directory
task ndkBuild(type: Exec, description: 'Compile JNI source via NDK') {
def ndkDir = android.ndkDirectory
commandLine "$ndkDir/ndk-build",
'-C', file('src/main/jni').absolutePath, // relative path to jni source
'NDK_LIBS_OUT=../jniLibs',
'-j', Runtime.runtime.availableProcessors(),
'all',
'NDK_DEBUG=1'
}
task ndkClean(type: Exec, description: 'Clean JNI object files') {
def ndkDir = android.ndkDirectory
commandLine "$ndkDir/ndk-build",
'-C', file('src/main/jni').absolutePath, // relative path to jni source
'NDK_LIBS_OUT=../jniLibs',
'clean'
}
// add this task as a dependency of Java compilation
tasks.withType(JavaCompile) {
compileTask -> compileTask.dependsOn(['ndkBuild'])
}
clean.dependsOn(['ndkClean'])
sourceSets.main {
jni.srcDirs = []
//jniLibs.srcDir 'src/main/libs'
}
buildTypes {
debug {
debuggable true
}
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile 'org.apache.commons:commons-io:1.3.2'
compile 'com.android.support:appcompat-v7:23.1.1'
compile project(':libraries:opencv')
}
Need I to change something on app grandle or anybody have some suggestion?
Could you suggest me some links to follow or explain step by step how can I solve it?
EDIT :
adding the jcenter to gradle.build resolves the issue:
buildscript {
repositories {
mavenLocal()
mavenCentral()
jcenter()
}
Click Ok for gradle wrapper or go manually at build.gradle and update the following line :
**classpath 'com.android.tools.build:gradle:3.2.1'**
Just click OK for Studio to automatically perform the Gradle configuration.

Error:(85, 0) Could not get unknown property 'compileJava' for project ':app' of type org.gradle.api.Project [duplicate]

In my android application I need to generate source code and use it in the app.
For that I created task genSources (using tutorials) for source generation. It works correctly if run it separately.
In my case I need to run source code generation automatically.
From tutorial I found out the following command:
compileJava.dependsOn(genSources)
but that is unknown command for the apply plugin: 'com.android.library'
gradle throws following exception:
Error:(35, 0) Could not find property 'compileJava' on project ':data'.
Looks like it can be used with apply plugin: 'Java'
but I cannot use these 2 plugins together
How can I solve this issue and generate needed source code before compilation?
build.gradle
apply plugin: 'com.android.library'
configurations {pmd}
android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
defaultConfig {
minSdkVersion 19
targetSdkVersion 21
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
buildscript {
repositories {
maven {
url "http://repo1.maven.org/maven2/"
}
}
dependencies {
classpath group: 'net.sourceforge.fmpp', name: 'fmpp', version: '0.9.14'
}
ant.taskdef(name: 'fmpp', classname:'fmpp.tools.AntTask', classpath: buildscript.configurations.classpath.asPath)
}
task genSources << {
println "Generating sources...."
ant.fmpp configuration:"src/main/resources/codegen/config.fmpp",
sourceRoot:"src/main/resources/codegen/templates",
outputRoot:"target/generated-sources/main/java";
}
compileJava.dependsOn(genSources)
sourceSets {
main {
java {
srcDir 'target/generated-sources/main/java'
}
}
}
dependencies {
...
}
UPDATED
I was found some solution which at least not throw exception
gradle.projectsEvaluated {
compileJava.dependsOn(genSources)
}
Then I execute gradle build but nothing happens
With gradle 2.2+ this should work:
tasks.withType(JavaCompile) {
compileTask -> compileTask.dependsOn genSources
}
If you also want it to happen when you evaluate (e.g. when syncing your project with gradle in android studio) you can do it like this:
gradle.projectsEvaluated {
preBuild.dependsOn genSources
}

How to use Gradle to generate JavaDoc in Android Studio?

I can not find any documentation on how to configure my Gradle file to create the JavaDoc for my project. I already tried some snippets from SO and blog articles but none of them seem to work or they do not provide context.
This is my Gradle file. What do I need to do to add a task to generate JavaDoc?
import org.apache.tools.ant.taskdefs.condition.Os
apply plugin: 'com.android.library'
android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
defaultConfig {
minSdkVersion 15
targetSdkVersion 21
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:21.0.3'
}
In our projects we added the following to the app's build.gradle:
android.applicationVariants.all { variant ->
task("generate${variant.name.capitalize()}Javadoc", type: Javadoc) {
description "Generates Javadoc for $variant.name."
source = variant.javaCompile.source
ext.androidJar = "${android.sdkDirectory}/platforms/${android.compileSdkVersion}/android.jar"
classpath = files(variant.javaCompile.classpath.files) + files(ext.androidJar)
options.links("http://docs.oracle.com/javase/7/docs/api/");
options.links("http://d.android.com/reference/");
}
}
This will add tasks to the build of the form generate<build_variant>Javadoc. So let's say you have a free and a pro version of your app, this would add tasks like:
generateFreeDebugJavadoc
generateFreeReleaseJavadoc
generateProDebugJavadoc
generateProReleaseJavadoc
Hope this helps
In android studio, write a gradle task of type Javadoc :
task createJavadocs (type: Javadoc)
{
source = project.android.sourceSets.main.java.srcDirs
options.linkSource true
classpath += project.files(project.android.getBootClasspath().join(File.pathSeparator))
failOnError false
}
Simply execute this task will create javadocs.

Gradle. How to generate source code before compilation in android app

In my android application I need to generate source code and use it in the app.
For that I created task genSources (using tutorials) for source generation. It works correctly if run it separately.
In my case I need to run source code generation automatically.
From tutorial I found out the following command:
compileJava.dependsOn(genSources)
but that is unknown command for the apply plugin: 'com.android.library'
gradle throws following exception:
Error:(35, 0) Could not find property 'compileJava' on project ':data'.
Looks like it can be used with apply plugin: 'Java'
but I cannot use these 2 plugins together
How can I solve this issue and generate needed source code before compilation?
build.gradle
apply plugin: 'com.android.library'
configurations {pmd}
android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
defaultConfig {
minSdkVersion 19
targetSdkVersion 21
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
buildscript {
repositories {
maven {
url "http://repo1.maven.org/maven2/"
}
}
dependencies {
classpath group: 'net.sourceforge.fmpp', name: 'fmpp', version: '0.9.14'
}
ant.taskdef(name: 'fmpp', classname:'fmpp.tools.AntTask', classpath: buildscript.configurations.classpath.asPath)
}
task genSources << {
println "Generating sources...."
ant.fmpp configuration:"src/main/resources/codegen/config.fmpp",
sourceRoot:"src/main/resources/codegen/templates",
outputRoot:"target/generated-sources/main/java";
}
compileJava.dependsOn(genSources)
sourceSets {
main {
java {
srcDir 'target/generated-sources/main/java'
}
}
}
dependencies {
...
}
UPDATED
I was found some solution which at least not throw exception
gradle.projectsEvaluated {
compileJava.dependsOn(genSources)
}
Then I execute gradle build but nothing happens
With gradle 2.2+ this should work:
tasks.withType(JavaCompile) {
compileTask -> compileTask.dependsOn genSources
}
If you also want it to happen when you evaluate (e.g. when syncing your project with gradle in android studio) you can do it like this:
gradle.projectsEvaluated {
preBuild.dependsOn genSources
}

Android Studio - No such property: baseName for class

I am trying to add Dexguard to Android Studio. I have followed the guidelines so my build.gradle is the following:
buildscript {
repositories {
mavenCentral()
flatDir { dirs '/Users/XXXX/Desktop/DexGuard5.3.00/lib' }
}
dependencies {
classpath 'com.android.tools.build:gradle:0.5.4'
classpath ':dexguard:'
}
}
apply plugin: 'dexguard'
android {
compileSdkVersion 19
buildToolsVersion "19.0.3"
defaultConfig {
minSdkVersion 9
targetSdkVersion 19
versionCode 1
versionName "1.0"
}
buildTypes {
debug {
proguardFile plugin.getDefaultDexGuardFile('dexguard-debug.pro')
proguardFile 'dexguard-project.txt'
proguardFile 'proguard-project.txt'
}
release {
proguardFile plugin.getDefaultDexGuardFile('dexguard-release.pro')
proguardFile 'dexguard-project.txt'
proguardFile 'proguard-project.txt'
}
}
}
dependencies {
compile 'com.android.support:support-v4:19.0.1'
compile 'com.android.support:appcompat-v7:19.0.1'
compile fileTree(dir: 'libs', include: ['*.jar'])
}
Then I try to build the project and I get the following error:
Error:A problem occurred configuring project ':XXXX'.
No such property: baseName for class: com.android.build.gradle.internal.variant.ApplicationVariantData
Has anyone experienced such problem again?
Thank you in advance!
The Gradle plugin for DexGuard 5.3.00 is compatible with the Android plugin 0.5.1, so you should adapt the class path at the top of the file.
You probably want to install the latest version of the Gradle plugin though. At this time of writing, the Gradle plugin for DexGuard 5.5 is compatible with the Android plugin 0.9.0.
As a reference, you can always find working sample projects with build files in DexGuard's samples directory.
First you can try to add nexusUsername=123 nexusPassword=123 in the "project/maven_push.gradle"
Then if it report "Error:Could not find property 'allJava' on source set main."
you can try this:
task androidJavadocs(type: Javadoc) {
// comment it if you find
//source = android.sourceSets.main.allJava
}
task androidJavadocsJar(type: Jar) {
classifier = 'javadoc'
//basename = artifact_id
// comment it if you find
//from android.sourceSets.main.allSource
}
task androidSourcesJar(type: Jar) {
classifier = 'sources'
//basename = artifact_id
////comment it if you find
//from android.sourceSets.main.allSource
}
Last it‘s not my answer ,I found it in an small blog~~~Thanks to the authoer ,it sloved my problems~
Good luck to you ~

Categories

Resources