Showing posts with label gradle. Show all posts
Showing posts with label gradle. Show all posts

Friday, 19 June 2015

Error Solving time - Android Studio - bad class file magic (cafebabe) or version (0034.0000) android studio

My friend got this error when he tried to import a project from Github, he asked me to try and see and I got the same issue as well. Finally we found that the issue was caused by the java compiler version.
Android supports 1.7 jdk version and if you are using a 1.8 version you might face this error.

This error came into picture when we tried to run the application, the normal gradle build was clean. On running the app gradle popped up with,
Local path doesn't exist 
and the cause was shown as
bad class file magic (cafebabe) or version (0034.0000) android studio

The fix:
1) Go to File > Other Settings > Default Settings > Build, Execution, Deployment > Compiler > Java Compiler, and change the Project bytecode version to 1.7

2)Go to File > Project Structure > SDK Location, here change the JDK locations path to that of a 1.7 version as below, for mac users give the jdk path till the Home folder.

Now try to build and run the project, it will be successfull. Thanks


Tuesday, 16 June 2015

Error Solving time - Android Studio - peer not authenticated

I had earlier worked on a studio project in a different machine, and after a while I thought of doing some modifications. Thankfully, I had a back up and I tried to open that project in studio in my new machine. It came up with the following error after the gradle build:

peer not authenticated

Here isthe solution, try changing the your root build.gradle's repository block as follows

repositories {
    jcenter {
        url "http://jcenter.bintray.com/"    }
}

repositories {
    maven {
        url "http://repo1.maven.org/maven2"    }
}

and rebuild your project, hopefully your error might be gone.
Happy coding :)

Friday, 5 June 2015

Adding gradle dependencies when library package name is not known

Im an android developer who recently moved to Android Studio. I had this problem of finding a library dependency name that I needed to declare in the gradle. The problem started when I was trying to add the Volley library to my project, I searched all over to find the relevant package of volley which needs to be declared in the dependency set and when I tried to use the
https://android.googlesource.com/platform/frameworks/volley
The gradle build failed, and I couldnt find a proper package name. So, I thought to share with you how to add a dependency whose package name you don't know in the android studio gradle. Please follow these steps:

  1. Right click your project name (say app)
  2. Open Module Settings
  3. Select Dependencies tab
  4. Click on the + sign in the top right
  5. Choose Library Dependency
  6. In the window that opens type the library file's name(say volley) 
  7. Double click on any library file and click Ok

You will see the dependency added in your gradle and the gradle auto sync has been initiated.

Tuesday, 26 May 2015

Android Studio and Gradle in brief

The features of the Android Studio consist of the following:
  1. Intellij or the intelligent code editor -  provides powerful code editing, code completion, refactoring etc. so that developers can save a lot of time. This feature was available with the ADT bundle as well which was used for android development earlier.
  2.  UI - The new Studio is shaped for better developer interactions. Easily accessible tools and settings and all other development related buttons are their within reach and there is no need to fish around much. Also the Layout Editors are better designed and layout previews are more real looking.
  3.  Rich AVD - The AVD manager has a rich set of devices in all shapes and sizes. This is one great boon.
  4.  Built in google cloud support.
  5.  Build tools - This is one of the most confusing point for developers who switched from eclipse. I would be going to this in detail hence.
    • Android Studio makes use of the Gradle build tools which is an automated build toolkit, basically a plugin. It consists of a set of files to configure and manage the build process. The scripts are based on the Groovy programming language.  
    • Compared to Eclipse IDE, where the developers were unaware about the backend apk building process, Android studio’s Gradle allows a seamless way for developers to manage their builds. With this plugin you will be able to build different versions of the same project like paid, unpaid or device specific apks etc. Developers can also trigger the build from command line as well.
    • The gradle allows including dependencies from within your local repos as well as remote repos. The gradle build normally takes place by assuming a default project convention or structure. It also gives you the freedom to alter your project structure; only, you have to make sure to configure the build files accordingly.

There are two levels of build files: module build file and project build file.  The project level build file is the topmost and it will contain basic information. An example project gradle file is as follows:
buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:1.0.0'
         // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}
 allprojects {
    repositories {
        jcenter()
    }
}

This file simply states that the build is based on the Android plugin and all the remote libraries will be obtained through the jcenter repository.
The Module build file contains the module wise build configurations. It also allows                 you override the main manifest file setting and configure custom packaging/compiling              option etc.

apply plugin: 'com.android.application'

android {
    compileSdkVersion 20
    buildToolsVersion "21.1.2"

    defaultConfig {
        applicationId "com.demo.sample"
        minSdkVersion 19
        targetSdkVersion 20
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
debug {
            debuggable true
        }

    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.google.android.gms:play-services:+'
}