Wednesday, October 21, 2015

Changing the .apk file's name in Android Studio

This is here, so I can remember next time. Use it if you will!

My version of Android Studio ( 1.4 ) does not allow you to change the name of the file produced by "Generate Signed APK...". At least if it does, I have no idea where.

So, to get an .apk that says something other than "app-release.apk" you need to modify your "build.gradle (Module:app) file by including the italicized code in the code below:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.1"
    defaultConfig {
        applicationId "ca.jlcreative.discountcalculator"
        minSdkVersion 10
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            applicationVariants.all { variant ->
                variant.outputs.each { output ->
                    def newName = output.outputFile.name
                    newName = newName.replace("app", "$defaultConfig.applicationId")
                    output.outputFile = new File(output.outputFile.parent, newName)
                }
            }
        }
    }
    productFlavors {
    }
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    compile 'com.android.support:appcompat-v7:23.0.1'
    compile 'com.google.android.gms:play-services-ads:7.0.0'
    compile 'org.apache.commons:commons-lang3:3.4'
    compile 'com.android.support:preference-v7:23.0.1'
}

Wednesday, June 3, 2015

Customizing the Netbeans RPC Installer for Product Version

If you build a NetBeans RCP application using the NetBeans platform the "Package As" menu option, you'll find that when you build a new version of the application, users are unable to install it. The Netbeans installer will not re-install and application and it "thinks" that the new install, is the same version as the old install. This is because of a hard-coded (1.0.0.0.0) string in the following files, which are used to create the installation package:

product.version in {nbdir}\harness\nbi\stub\ext\infra\build\products\helloworld\build.properties

and the version attribute in <create-bundle> <component in {nbdir}\harness\nbi\stub\build.xml



To make this dynamic, so you can change versions from your build, you will need to modify the following files:

in {nbdir}\harness\nbi\stub\ext\infra\build\products\helloworld\build.properties

change 67 to:

#Changed from the hard coded "1.0.0.0.0"
product.version={product-version}


on line 166 in {nbdir}\harness\nbi\stub\build.xml


<component uid="${main.product.uid}" version="${product-version}"/> <!-- changed version to version="${product-version}" from hard coded string version="1.0.0.0.0"-->


In template.xml:

after line 141, 131 and 122 add the following:

<replacefilter token="{product-version}"     value="${product-version}"/> <!-- Added to do the substitution -->

after line 84:

<property name="product-version"  value="${suite.props.app.version}"/>


And finally, in {project}\nbproject\project.properties"

add:
# application / product version MUST be formated as N.N.N.N.N
app.version=15.0.0.0.0


Since you've changed Netbeans "installed" code, you might want to place it under version control.

This shouldn't be so hard. But like everything else in Netbeans, there you have it. Your new install will over-right your old ones now.



Wednesday, April 1, 2015

Eclipse with Android Studio Hangs

Is Eclipse with Android Studio installed failing to load?

Is it hanging somewhere loading an Android component?

Try unplugging your Android device you are using to debug from the USB cable.

Works for me, every time ;)

Friday, August 29, 2014

Switching an Android Menu Icon via Themes

First, edit attrs.xml to include the name:  <attr name="undo_icon"

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <attr name="undo_icon" format="reference" />
</resources>

Then, edit the styles.xml to define the style: <item name="undo_icon">

<resources>
    <!--
        Base application theme, dependent on API level. This theme is replaced
        by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
    -->
    <style name="AppBaseTheme" parent="Theme.AppCompat.Light">
        <!--
            Theme customizations available in newer API levels can go in
            res/values-vXX/styles.xml, while customizations related to
            backward-compatibility can go here.
        -->     
    </style>

    <!-- Application theme. -->
    <style name="AppThemeLight" parent="AppBaseTheme">
        <!-- All customizations that are NOT specific to a particular API-level can go here. -->
        <item name="undo_icon">@drawable/halo_dark_content_undo</item>       
    </style>
    <style name="AppThemeDark" parent="AppBaseTheme">
        <!-- All customizations that are NOT specific to a particular API-level can go here. -->
        <item name="undo_icon">@drawable/halo_light_content_undo</item>
    </style>
</resources>

Finally, define the menu.xml: android:icon="?undo_icon"

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
    <item
        android:id="@+id/menu_undo"
        android:icon="?undo_icon"
        android:title="Undo"
        android:titleCondensed="Undo">
    </item>
</menu>

In the Manifest: android:theme="@style/AppThemeLight" >  OR switch dynamically via Context.setTheme

<application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppThemeLight" >


To reference in code:

        TypedValue typedValue = new TypedValue();
        getTheme().resolveAttribute(R.attr.
undo_icon, typedValue, true);
        btnUndo.setImageResource(typedValue.resourceId);


Thursday, August 28, 2014

How to fix Android SDK Content Loader stuck at 0% in Eclipse

Have you encountered the case where Eclipse hangs upon startup, in particular when you are developing an Android applications with Android SDK?

When that happens you see "Android SDK Content Loader" stuck at 0% in the bottom right hand of the Eclipse status bar.

There are four things you can try...

Solution 1:
  1. Make sure that eclipse is not active. If it is active kill eclipse from the processes tab of the task manager 
  2. Check if the adb process is running. If so, kill the adb process, and restart Eclipse. 

 Solution 2: (Works best for me, and likely the safest)
  1.  Make sure that eclipse is not active. If it is active kill eclipse from the processes tab of the task manager
  2. From the command line run: C:\eclipse\eclipse.exe -clean

Solution 3:
  1. Make sure that eclipse is not active. If it is active kill eclipse from the processes tab of the task manager
  2. Open %USERPROFILE%/ (You can locate this folder from desktop) (or paste it into Explorer on windows)
  3. Go to .android folder (This may be a hidden folder)
  4. Delete the folder "cache" which is located inside .android folder
  5. Delete the file ddms.cfg which is located inside .android folder
  6. Start Eclipse
Solution 4: (Most drastic, and one I have not tried)

Go to your workspace directory \workspace\.metadata\.plugins\org.eclipse.core.resources\\.projects

  1. Copy .projects folder to make a temporary backup.
  2. Now Delete .projects folder from workspace directory. (you will not loose your projects)
  3. Start Eclipse and wait for all progress ends at right/bottom corner. Once completed all processes, shutdown Eclipse.
  4. Paste .projects folder which you have backup earlier to \workspace\.metadata\.plugins\org.eclipse.core.resources\ directory. Overwrite existing .projects folder.
  5. Start Eclipse again. And all will work.
In above scenario Eclipse will automatically find your earlier projects. You do not have to import them manually.

Good Luck

Wednesday, July 2, 2014

NetBeans RCP installer version upgrade

So every other installation package I've ever used, allows you to upgrade your application, by changing its version number.

Not so with the NetBeans packager.

The NetBeans platform installer uses common code located in {nbdir}\harness\nbi\stub
Customizing these files and sources allows you to brand you installer, which is all nice, but you would not expect to have to customize these files in order to get your program to upgrade.

Product version is controlled in two files, both which need to be changed.
  1. product.version in {nbdir}\harness\nbi\stub\ext\infra\build\products\helloworld\build.properties
  2. version attribute in create-bundle > component in {nbdir}\harness\nbi\stub\build.xml 
These values must be changed, in order for the installer to allow the installation.

Stupid, but there you have it. Some day, when I have time, I'll try and automate it all.
 

Tuesday, May 27, 2014

ERROR_NOT_MARKET_MANAGED in com.google.android.vending.licensing

So, after spending more than a day scratching my head over the fact that I constantly got the error code: ERROR_NOT_MARKET_MANAGED returned via my callback in the Google licensing API, the solution, as it usually does, turned out to be a simple answer.

Regardless of the fact that all Googles developer documentation tells you it's good enough to upload your APK to the product page for license testing to work, this is not true.

To get it to work, you need to publish you app. At first thought, I was afraid this would make it "live", but as long as your APK is in the Alpha or Beta Testing section, you'll be ok.