How to push project source code to BitBucket repository from Android Studio

Hi Guys, In this post, I’ll give details about push project source code to Bitbucket repository from Android Studio.

When you started working on a project in Android Studio, you may want to store the project code to safe remote server. For this purpose its recommended to use Bitbucket repository system. Which will allow you to create repository and push all source code safely. Important feature it’ll provide you all Git features with Project management system. So you can create Multiple branches and Tags and manage your source code safely even with multiple developers working on a same project.

You need to have BitBucket Login for creating new repository, If you not have you can create a Bitbucket login here. After creating Account, Login to BitBucket website and Create a new repository. And get the link for new repository. It’ll be used in Android Studio later.

Ok, Now Open Android Studio with your project source code. Go through the below steps to Push project.

In Android Studio, Go to VCS menu -> Select Enable Version Control Integration…

project source code

You’ll see Popup to select version Control System. here select Git and click OK.

You’ll see your Project files changes to orange colour.

Now right click Project, it will display a menu. Goto Git->Select Add

After clicking on Add, Project files will change to green colour

Now Again right click on Project and in menu Go to Git-> Select Commit Directory…

It’ll display a Commit Changes dialog, Enter your Commit Message and click Commit.

Now right Click on Project Source Code, in menu Go to Git-> Select Repository -> and then Select Push… or else you can type shortcut keys Ctrl+Shift+K .

You’ll Push Commits dialog, In this dialog you’ll see master –> Define Remote.

Click on Define Remote, It’ll display a Define Remote dialog. In this dialog paste the URL(that is taken in Bitbucket after creating repository). And click OK.

It’ll show all the Committed files and message you entered before when committing directory. Now Click on Push. It’ll push all code files to Bitbucket repository.

Now if you go to bitbucket website in a browser and open your repository and refresh it. You’ll see project source code pushed safely to your repository.

That’s it.

Hope it helps somebody.

💡

 

 

 

 

 

 

Issues after updating to Android Studio 2.0v

In this post, I just like to sum up all the issues faced after updating Android version.

After updating to Android Studio 2.0v, you may see following issues.

You’ll be asked to install latest gradle version to enable Instant Run. you think it helps and installs the latest Gradle version.

Now, your problems starts You may be able build project. But couldn’t able to run the project. When you run the project, you’ll see Out of memory exception as below. 😐

Error:java.lang.OutOfMemoryError: Java heap space.
Please assign more memory to Gradle in the project's gradle.properties file.
For example, the following line, in the gradle.properties file, sets the maximum Java heap size to 1,024 MB:
<em>org.gradle.jvmargs=-Xmx1024m</em>
<a href="http://www.gradle.org/docs/current/userguide/build_environment.html">Read Gradle's configuration guide</a><br><a href="http://docs.oracle.com/javase/7/docs/technotes/guides/vm/gc-ergonomics.html">Read about Java's heap size</a>

I tried different ways to increase the memory, like changing the memory values in gradle.properties file

org.gradle.jvmargs=-Xmx2048m -XX\:MaxPermSize\=512m

and changing values in studio64.exe.vmoptions file in C:\Program Files\Android\Android Studio\bin folder

-Xms512m
-Xmx2048m

but not worked. 🙁

The only thing that worked for me is adding javaMaxHeapSize value of dexOptions in app’s build.gradle file.

android{
  ....
  ....
  dexOptions {
     javaMaxHeapSize "2g"
  }
}

this fixes the OutOfMemoryError issue. The reason for this issue is the latest version gradle needs more memory to build the app.

And after fixing You may see Multiple dex files issue. For me I get this error

Cause: com.android.dex.DexException: Multiple dex files define Lcom/google/zxing/BarcodeFormat;  😮

I tried following to fix this issue

defaultConfig {
..
// Enabling multidex support.
multiDexEnabled true
}

Which resulted same issue in different way 😡

Error:Execution failed for task ':app:transformClassesWithJarMergingForDebug'.
> com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: com/google/zxing/BarcodeFormat.class

in inconsistent location 'C:\Users\employee2\AppData\Local\Android\sdk\add-ons\addon-google_apis-google-19-1'
(Expected 'C:\Users\employee2\AppData\Local\Android\sdk\add-ons\addon-google_apis-google-19')

Error:Error converting bytecode to dex:

So, I removed that multiDexEnabled true line and search for the BarcodeFormat class usage in project. I finally find out that same dependencies library added in module’s and app’s  build.gradle file. I just commented dependencies library in app’s build.gradle file fixed the issue.  😎

So, finally After fixing all issues and you’ll be able to run the app. 

And then, now you made some code changes and run the app. App won’t run on device with latest code changes. In the Android Studio Run tab you’ll see “No changes”.  What! 😮

The reason for this Instant Run not recognizes certain code changes, and it also needs latest android API.

instant_run

So, the only option to see your code changes effect in app and run on device, is disable Instant Run. Please see following image to disable

after updating

That’s it now you able to see code changes by running the app on device.  😎

 

Hope it saves somebodies time. 💡

 

You may also interested in

 

To download latest version, no Update and Restart button in Android Studio

In Android Studio, you may see “A new version Android Studio available” popup message at the top right corner, whenever latest version available to update.

latest version

When you click on that popup message link, you’ll see a dialog with a button, which allow you Update and Restart Android Studio. But at times you may not see Update and Restart button, as shown below.

dl_issue2

As shown in above image, There’s no button to Update version. You may be wonder why and how you can get install the latest version.

Solution to download latest version:

Here is the solution to fix that issue.

Goto Settings-> Appearance & Behavior -> System Setting -> Click on Updates and then in the right panel you’ll Check Now button.

dl_issue3

Click on Check Now button. It’ll check for the latest update and fixes download issue. Now close the Setting window. And try again to Click on “A new version Android Studio available” popup message link.

You’ll see Update and Restart button. Click on it You’ll get the latest version installed.

dl_issue4

 

Hope it helps somebody.

🙂

You may also interested in

 

Integrate BitBucket Plug-in Android Studio

This BitBucket Plugin removed in Jetbrains website now, so below link not working. Good news is this Plug is not required anymore. You may directly start from Enable VCS step below in Android Studio and then proceed next steps. Or else you may look at another detailed post here.

You can push project to Bit Bucket without using Terminal in Android Studio. To do that you need a Bitbucket plug-in.

Install BitBucket Plug-in

You can download BitBucket plugin from this link. After downloading zip file don’t unzip it. Goto Android Studio, press Ctrl+Alt+S, and search for Plugins in left panel. You will see Plugins tab in right panel.

as_bb_plugin

Click on Install plugin from disk,

as_bb_plugin-1

Select downloaded BitBucket zip file and Click on Apply,

BitBucket Plug-in

It’ll ask to restart Android Studio. Click Restart button.

 

Enable VCS

After restarting, Your BitBucket Plug in is installed and ready to use. Now to start Push all your project to BitBucket.

Goto- VCS menu-> and select Enable Version Control Integration.

as_bb_plugin-3

You’ll be prompted to select Version control system for the project root, here select Git as Bit Bucket uses git system

as_bb_plugin-4

Now Goto, BitBucket website and Create a new repository with same name as project.

as_bb_plugin-5

You’ll see Command line syntax to init push code. Just copy the bitbucket origin Url as shown below.

as_bb_plugin-6

Now Goto AndroidStudio, select project and Git->Add as shown below

as_bb_plugin-9

And then Commit the changes as shown below.

as_bb_plugin-8

Enter initial Comment for project and then select Commit and Push as shown below.

as_bb_plugin-10

Here, You’ll ask to define remote,

as_bb_plugin-11

Click on it and Enter URL that we copied from Bit Bucket command line syntax.

as_bb_plugin-12

You’ll be able to Push code to the repository. Click on Push button

as_bb_plugin-13

Now Go to, Bit bucket website you’ll see project files Committed to your repository.

as_bb_plugin-14

That’s it. You just Pushed all your Project to Bit bucket without using Terminal window.

Hope it helps somebody.

Cheers.

You may also interested in

Create new Class extends a SuperClass- Android Studio

In Android studio, If you want to create a new Class extends a SuperClass, built-in menu doesn’t provide option for it.

Create a Class extends a SuperClass

Where as you can only Create a new Class and then manually write down extends Superclass.

as_file1
Image 1
as_file1-2
Image 2

To add Create new Class which extends a SuperClass, you need to Create a new Template

Press Ctrl+Alt+S to open Settings  window, here search for File and Code Templates

as_file1-3
Image 3

Click + button to add new template, give a name as Inheritance(you can give any name) and write this below code

#if (${PACKAGE_NAME} && ${PACKAGE_NAME} != “”)package ${PACKAGE_NAME};#end
#parse(“File Header.java”)
public class ${NAME} extends ${SUPERCLASS} {
}

Apply it and the Click Ok button. as shown below

as_file1-4
Image 4

Now go to project and try to create new class as shown Image 1 above..

and  you’ll see newly added template in dropdown as shown below.

as_file1-5

Select it and then you’ll be asked to enter Super class name. Enter your Super class name.

SuperClass

That’s it.

You’ll see new Class created with SuperClass.

Hope it helps somebody.

You may also interested in

 

Gradle DSL method not found – Android Studio

After importing Eclipse project to Android Studio. When you run the project, you may see following error message as, Gradle DSL not found: ‘android()’

Gradle DSL

Solution to fix this Gradle DSL method issue

open Top-level build.gradle file of the project

as_gbuild_file

And remove the following code lines.

android {
compileSdkVersion 21
buildToolsVersion '21.1.2'
}

And then click Sync menu button, fixes the issue.

sync

And another possible issue is,

Gradle DSL method not found: ‘runProguard()’

At times when you import a downloaded sample project in to Android Studio, see following error message as, Gradle DSL not found: ‘runProguard()’

app_gradlefile-2

Solution to fix this Gradle DSL method issue

open app’s build.gradle file of the project

app_gradlefile

In this file you can see following code snippet

buildTypes {
    release {
        runProguard false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}

In the above code runProguard false causing the issue. Change that line to

minifyEnabled false

Now click Sync menu button, issue will be fixed. I see the reason for this is runProguard has been renamed to minifyEnabled in version 0.14.0 or more in Gradle.

Hope it helps somebody. 😎

You may be also interested in

Android Studio ADB wipes out logcat quickly when app crashes

Android Studio ADB wipes out logcat quickly

At time we may face this kind of annoying issue. In Android Studio, in Android tab ADB wipes out log cat data quickly when app crashes. And makes us not able to find out the code issue.

wipes out

To solve this issue, in Android tab on right side you can see dropdown to select the log filter

logcat2

Select Edit Filter Configuration, and you will see this window

logcat3

In this window, set your application Package Name as shown in  above image. You can set any Filter Name text. and Click OK.

Now, if app crashes, it will show the log data.

Hope it helps somebody…

 

You may also interested in

Could not resolve com.android.support:support-v4:22.0.0, Android Studio

While implementing Push Notifications, I get this error Could not resolve all dependencies for configuration

I’ve installed Google Play Services and Google Repository using SDK manager

not resolve

and added the following dependencies in gradle file

dependencies {
   compile 'com.google.android.gms:play-services-gcm:7.0.0'
   ....
}

When I run the app, I see following error,

Could not resolve all dependencies for configuration ':library:_debugCompile'.
> Could not resolve com.android.support:support-v4:22.0.0.
Required by:
:library:unspecified > com.google.android.gms:play-services:7.0.0 > com.google.android.gms:play-services-base:7.0.0
> No cached version of com.android.support:support-v4:22.0.0 available for offline mode.

After searching solution for a while, I found the issue is due to this  “You need to make sure you have Android Support Repository up to date – that is where Android Support Library dependencies are resolved.”

So, I installed Android Support Repository,

fix_issue
and Rebuild app… Fixed the issue.

Hope it helps somebody..

ref link: http://stackoverflow.com/a/29569756/341443

Generate signed APK file with Specific name Android Studio

In Android Studio, when clicked menu Build-> Generate Signed APK file, the dialogs displayed for generating APK file, doesn’t allow you to edit the APK file name. It just applies default app name to build file, unlike ADT Eclipse.

Solution:

We have to write Groovy code in Gradle build file to, Generate singed APK file with Specific name.

Here i’m just giving an example how we can write it.
For eg: If your app name is helloWorld, If you generate APK build file, it will creates helloWorld-release.apk file. But if you want to generate Apk file with appending version name, and change filename like “HelloWorld-1.0v.apk”.

In project open build.gradle file, you should have defaultConfig as below

defaultConfig {
    applicationId "com.sample.helloworld"
    minSdkVersion 14
    targetSdkVersion 14
    versionCode 1
    versionName '1.0'
}

in this build.gradle file, define a method just above the dependencies, as below

def appendVersionName(variant, defaultConfig) {
    variant.outputs.each { output ->
        if (output.zipAlign) {
            def file = output.outputFile
            def fileName = file.name.replace("helloWorld-release.apk", "HelloWorld-" + defaultConfig.versionName  + "v.apk")
            output.outputFile = new File(file.parent, fileName)
        }

        def file = output.packageApplication.outputFile
        def fileName = file.name.replace("helloWorld-release.apk", "HelloWorld-" + defaultConfig.versionName + "v.apk")
        output.packageApplication.outputFile = new File(file.parent, fileName)
    }
}

dependencies {
    compile files('libs/android-support-v13.jar')
    compile 'com.android.support:appcompat-v7:21.0.2'
}

then search for buildTypes, and call the appendVersionName method as shown below,

buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'

            applicationVariants.all { variant ->
                appendVersionName(variant, defaultConfig)
            }

        }
    }

That’s it. Now Goto Build-> Generate a Signed APK… just follow the dialog, click Finish, and you will see APK file created with your specified name.

Hope it helps somebody…

Cheers.. 🙂

ref link & credits: http://stackoverflow.com/a/22126638/341443

You may also interested in

How to debug project, Android Studio

Android Studio: Debug Project

This post is for beginners, to give basic understanding to debug project in Android Studio.

To debug Project, you have to place breakpoints at the code line, of a method or class, So the debugger will stop at that break point while debugging.
To place a break point just click on  work space left side border you can see red dot. To remove breakpoint just click on red dot again.

debug_2

To debug a project from starting screen of your app, You have to click on the Debug menu button, or Press Shift+ F9

debug_1
*generally, while debugging app slows down.

So, You can use another debug option to debug at a Specific Screen.
At times you may want to debug code in a Specific screen at a particular line for eg. on a Save button click event method.

So, Place a breakpoint at that particular onClick(View v) method.

debug_4

And just run the app by clicking Run menu button

debug_3

After running app on device or emulator, navigate to the Specific screen and just before clicking on Save button(button event where you want to debug code) in screen. Click on Attach debugger to Android Process menu button in Android Studio work space.

debug_5

You’ll see a dialog to select a process, here select your process (and wait for a moment for debugger to attach to process) and now click on the Save button in that Specific screen. You can see Debug console at the bottom and debugger waits at break point at a specific line to enable you start debugging.

debug project

Here I just like to explain few useful debug console button functionalities

Press F8 or click on the below debug console button icon, to move debugger to next line.. and so on…

debug_7

Press F7 or click on the below debug console button icon, to move debugger to in to a inner class method.(This is very rarely used). Use it whenever a method call is escaping from debugging.

debug_8

Press F9 or click on the below debug console button icon, to execute code up to next break point..

debug_9

Press Ctrl+F2 or click on the below debug console button icon, to stop debugger execution, when you click on this button, debugger stops execution and app runs normally.

debug_10

these buttons are mainly used for debugging. If you understand these button functions first then You can see and understand other button functions easily.

You can see all variables data and instances data of Specific screen in Variable section…

debug_11

Hope it makes sense and helps somebody.

cheers 🙂

You may also interested in

12