View Single Post
Old 10-12-2010, 07:33 PM   #1
KukMan
Member
KukMan plays well with othersKukMan plays well with othersKukMan plays well with othersKukMan plays well with othersKukMan plays well with othersKukMan plays well with othersKukMan plays well with othersKukMan plays well with othersKukMan plays well with othersKukMan plays well with othersKukMan plays well with others
 
Posts: 12
Karma: 2600
Join Date: Oct 2010
Device: Kindle 3 Wi-fi US
Guide: How to write Kindlets

Big thanks for adq and his lj entries.
All what I'll write I tested on my Kindle 3 wifi only.
Your must have jailbreaked Kindle to do this, have some skills with Linux systems and with Java.
  1. First of all, we need get KDK jars files. You can copy it from your Kindle. Main KDK jar is located at /opt/amazon/ebook/lib/Kindlet-1.1.jar. Also you can pull off all jars from /opt/amazon/ebook/lib and /opt/amazon/ebook/sdk/lib folders.
  2. Create Java project in your fav IDE ( I use NetBeans ). Add Kindlet-1.1.jar as library to your project ( depends from your IDE ). Hello World Example Kindlet is under spoiler. You would be able to compile it at this step.

    Spoiler:
    Code:
    package test;
    
    
    import com.amazon.kindle.kindlet.AbstractKindlet;
    import com.amazon.kindle.kindlet.KindletContext;
    import com.amazon.kindle.kindlet.ui.KTextArea;
    
    public class Main  extends AbstractKindlet {
            
            private KindletContext ctx;
    
            public void create(KindletContext context) {
                    this.ctx = context;
            }
    
            public void start() {
                    try {
                            ctx.getRootContainer().add(new KTextArea("Hello World!"));
                    } catch (Throwable t) {
                            t.printStackTrace();
                    }
            }
    }
  3. You must change Manifest file in your project. It's depends from you IDE also. You must add this lines to it:
    Code:
    Implementation-Title: Your_App_Name
    Implementation-Version: Your_App_Verion
    Implementation-Vendor: Your_Name
    Don't forget change lines with your data.
    At this step, we have jar file with valid Manifest file. You can try change filename from *.jar to *.azw2, copy it into documents folder on USB mass storage and run, but you wouldn't be able do this. This is normal.
    Note, that you can check manifest, unzip jar file and see it in META-INF folder.
  4. Create own keystore with pairs of keys for signing own kindlets. "keytool" helps us. For creating keystore execute this commands:
    Code:
    keytool -genkeypair -keystore developer.keystore -storepass YOURPASS_FOR_STORE -keypass YOURPASS_FOR_KEY -alias dkYOUR_ALIAS -dname "CN=Unknown, OU=Unknown, O=Unknown, L=Unknown, ST=Unknown, C=Unknown" -validity 5300
    keytool -genkeypair -keystore developer.keystore -storepass YOURPASS_FOR_STORE -keypass YOURPASS_FOR_KEY -alias diYOUR_ALIAS -dname "CN=Unknown, OU=Unknown, O=Unknown, L=Unknown, ST=Unknown, C=Unknown" -validity 5300
    keytool -genkeypair -keystore developer.keystore -storepass YOURPASS_FOR_STORE -keypass YOURPASS_FOR_KEY -alias dnYOUR_ALIAS -dname "CN=Unknown, OU=Unknown, O=Unknown, L=Unknown, ST=Unknown, C=Unknown" -validity 5300
    Note, that dk, di and dn suffixes in aliases is necessary.
    Alias is case-insensitive. For example:
    Code:
    keytool -genkeypair -keystore developer.keystore -storepass passwork -keypass password -alias dnTest -dname "CN=Unknown, OU=Unknown, O=Unknown, L=Unknown, ST=Unknown, C=Unknown" -validity 5300
  5. Copy this keystore to /var/local/java/keystore/developer.keystore
  6. Sign jar file executing this command:
    Code:
    jarsigner -keystore KEYSTORE_FILE -storepass KEYSTORE_PASS JAR_FILE dkYOUR_ALIAS
    jarsigner -keystore KEYSTORE_FILE -storepass KEYSTORE_PASS JAR_FILE diYOUR_ALIAS
    jarsigner -keystore KEYSTORE_FILE -storepass KEYSTORE_PASS JAR_FILE dnYOUR_ALIAS
    For example:
    Code:
    jarsigner -keystore develop.keystore -storepass password ~/projects/test/dist/test.jar dnTest
  7. Copy signed jar into Kindle, rename it to *.azw2, and try to run.
    Note, that you must restart your Kindle after copying develop.keystore to it.

P.S. If you want to know more, you can read adq's entries in his LiveJournal about this.

P.S.S. I suggest create one public develop.keystore, and sign all free apps. It prevents problem with apps from different developers. Or how can I merge keystore from another developer with mine?

Last edited by KukMan; 10-12-2010 at 08:29 PM.
KukMan is offline   Reply With Quote