Showing posts with label Android Studio. Show all posts
Showing posts with label Android Studio. Show all posts

Friday, 15 December 2017

Fixing 'Error:Unsupported method: BaseConfig.getApplicationIdSuffix()' issue in Android Studio

Background

I tried importing an old android project into my Android Studio and the build was failing with following error -

Error:Unsupported method: BaseConfig.getApplicationIdSuffix().
The version of Gradle you connect to does not support that method.
To resolve the problem you can change/upgrade the target version of Gradle you connect to.
Alternatively, you can ignore this exception and read other information from the model.




Solution

As the error itself says solution is to upgrade gradle version.

Go to project level build.gradle. For me it looks like below -

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:1.2.3'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        jcenter()
    }
}


Just upgrade the gradle version from 1.2.3 (or whatever you have)  to 3.0.1. You can try upgrading to other higher versions as well. This is what worked for me. So the build.gradle looks like below -

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.0.1'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        jcenter()
    }
}




Once you do that click on "Try again" and the gradle sync should go through.



Sunday, 6 August 2017

Enabling Eclipse key map/shortcuts in Android Studio

Background

If you are from a developer using Eclipse then when you start using Android Studio then it becomes difficult to learn new shortcuts. For such cases Android Studio provides an option to use Eclipse shortcuts and in this post we will see how.

Enabling Eclipse key map/shortcuts in Android Studio

Go to 
  • Android Studio -> Preferences
Type in keymap in the searchbox. You should be able to see a keymap section -



Next select Eclipse or Eclipse(Mac OS X) whichever you are more comfortable with. Then click Apply and Ok.



You should be good to use Eclipse shortcuts now. No need to restart.


Related Links


Saturday, 1 April 2017

Android : URI is not registered (Settings | Project Settings | Schemas and DTDs)

Background

When you are developing android application you might sometime see following error on your layouts xml files in Android studio-
  • URI is not registered (Settings | Project Settings | Schemas and DTDs)


Everything seems correct except this error is persistent. Gradle sync works fine too. Lets see how we can resolve this.

Solution

  • Before we see how to resolve this issue make your layout file is in correct directory structure. It should be under layout folder which would be under res folder.




  • Now look at build variant tab at the bottom left of android Studio. You should see the current version set. It could be -
    • debug OR
    • release
In my case it was release. Just switch the version and then switch it back. In my case I switched it to release and then back to debug and the error was gone.


  •  If above 2 methods did not work out for you then Close all open tabs and reopen them. 
  • Last but not the least - restart Android Studio.
I know these are just silly workaround. Let me know which one works for you :)

 

Sunday, 27 November 2016

Adding and packaging wear module to your existing Android application

Background

Smart watches are slowing making their way into the market. They are quite expensive today but hoping prices will slash down with increase of technology. Anyway this post is aimed to add a wearable module to your existing Android app. This post expects you
  1. Have an existing Android application code
  2. Have it setup in latest Android Studio
So now that we have our prerequisites in place lets see how we can do this.

Step 1 : Adding a wearable  module to your Android application

If you have have your android application code opened in studio you simply need to 
  1. Open module settings
  2. Create on + (plus) button and select "Android Wear Module" .
  3. Next give your module name (NOTE : Make sure your wear module bundle id is same as your main android app bundle id)
  4. Next select activity
  5. Give your activity/layout name
  6. Click Finish


 Once you do this you should see a new module in your project with the name you provided during configuration. It will have its own set of java files, resource files, icons, manifest, build.gradle file etc.

You can go ahead and code your logic into this. This will run on your wearable device.


Step 2 : Packaging Wearable Apps

The way wearable app is distributed is by packaging it inside your handheld application (apk gets bundled inside) and when this app is installed on your phone/handheld device the wearable apk will get pushed to your wearable device.

To properly package a wearable module -
  1. Include all the permissions declared in the manifest file of the wearable app module in the manifest file of the handheld app module. For example, if you specify the VIBRATE permission for the wearable app, you must also add that permission to the handheld app.
  2. Ensure that both the wearable and handheld app modules have the same package name and version number.
  3. Declare a Gradle dependency in the handheld app's build.gradle file that points to the wearable app module: 

    Eg.

    dependencies {
        compile fileTree(dir: 'libs', include: ['*.jar'])
        testCompile 'junit:junit:4.12'
        compile 'com.android.support:appcompat-v7:23.4.0'
        compile 'com.android.support:support-v4:23.4.0'
        compile 'com.google.android.gms:play-services:9.0.0'
        wearApp project(':flashlightwear')
    }
    

  4. Click Build > Generate Signed APK.


How it works

  • Your android mobile/handheld application and your wearable application (apk) should be signed using same certificate (key). 
  • They must also have same package name and version number.
  • When you generate a release build if your handheld application your wearable apk will get bundled in your handheld apk.
  • When you install your handheld app on your mobile which is paired to your wearable device (eg smart watch) then wearable apk bundled within will be automatically pushed and installed on the wearable device.
  • You cannot take a call on which ones to keep or not keep. If you have an app installed on your mobile device and it has a wear module it will be installed on your wearable device. You cannot uninstall it unless you remove the app from your phone.

You should see a notification on your wear device that app is installed.


I have added wear module to a flashlight app that I had developer sometime back just to learn this stuff. You can check it out. Its available on playstore -


NOTES:
  1. Ensure that both the wearable and handheld app modules have the same package name and version number.
  2. Include all the permissions declared in the manifest file of the wearable app module in the manifest file of the handheld app module. 
  3.  Your android mobile/handheld application and your wearable application (apk) should be signed using same certificate (key).
  4. wearable apk gets automatically bundled with your handheld module and gets pushed to your wearable device once installed on handled device.



Related Links





t> UA-39527780-1 back to top