Tagged: android

Machine Scents


References

Animal Scents

There is a nice maven plugin and artifacts for checking application code against specific platform APIs.
Say, you want to make sure that your application code uses only those defined in Java 6? The Animal Sniffer Maven Plugin is just right plugin for that. Please check links above.

Machine Scents

I wrote some artifacts which each is a signature of Android APIs. Here comes how we can use it.

<dependencies>
  <dependency>
    <groupId>com.google.android</groupId>
    <artifactId>android</artifactId>
    <version>${android.version}</version>
    <scope>provided</scope>
  </dependency>
</dependencies>

<properties>
  <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
  <android.version>2.3.3</android.version>
  <android.api.level>10</android.api.level>
</properties>

<build>

  <plugins>
    <plugin>
      <groupId>com.jayway.maven.plugins.android.generation2</groupId>
      <artifactId>android-maven-plugin</artifactId>
      <configuration>
        <sdk>
          <platform>${android.api.level}</platform>
        </sdk>
        <apk>
          <metaIncludes>
            <metaInclude>services/**</metaInclude>
          </metaIncludes>
        </apk>
      </configuration>
    </plugin>

    <plugin>
      <groupId>org.codehaus.mojo</groupId>
      <artifactId>animal-sniffer-maven-plugin</artifactId>
      <executions>
        <execution>
          <id>check-against-android-api-signature</id>
          <goals>
            <goal>check</goal>
          </goals>
          <configuration>
            <includeJavaHome>false</includeJavaHome>
            <signature>
              <groupId>com.googlecode.jinahya</groupId>
              <artifactId>android-api-signature-${android.api.level}</artifactId>
              <version>1.0.2</version>
            </signature>
          </configuration>
        </execution>
      </executions>
    </plugin>
  </plugins>

</build>
Advertisements

adb shell date now


I don’t like iOS but I hate Android.

References

$

... $ adb shell date -s `date +"%Y%m%d.%H%M%S"`

>

PS ...> adb shell date -s $(get-date -format yyyyMMdd.HHmmss)

public class AdbShellDateNow {

    public static void main(final String[] args)
        throws java.io.IOException, InterruptedException {

        final long now = System.currentTimeMillis() / 1000L;
        final ProcessBuilder builder =
            new ProcessBuilder("adb", "shell", "date", Long.toString(now));
        builder.redirectErrorStream(true);
        builder.redirectOutput(ProcessBuilder.Redirect.INHERIT);

        final Process process = builder.start();
        process.waitFor();
    }
}

checking android signature with maven


I just found that android doesn’t like following line.

final Random random = ThreadLocalRandom.current(); // cool, isn't it?

Because there is no such class named java.util.concurrent.ThreadLocalRandom in Android runtime (at least 2.3.3).

Machine Scents

I made an artifact for maven users.

<project ...>
  <groupId>...</groupId>
  <artifactId>...</artifactId>
  <version>...</version>
  <packaging>apk</packaging>
  <dependencies>
    <dependency>
      <groupId>com.google.android</groupId>
      <artifactId>android</artifactId>
       <version>2.3.3</version>
      <scope>provided</scope>
    </dependency>
  </dependencies>
  <build>
    <plugins>
      <plugin>
        <groupId>com.jayway.maven.plugins.android.generation2</groupId>
        <artifactId>android-maven-plugin</artifactId>
        <version>3.6.1</version>
        <configuration>
          <sdk>
            <platform>10</platform>
          </sdk>
          <apk>
            <metaIncludes>
              <metaInclude>services/**</metaInclude>
            </metaIncludes>
          </apk>
        </configuration>
      </plugin>
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>animal-sniffer-maven-plugin</artifactId>
        <version>1.9</version>
        <executions>
          <execution>
            <id>check</id>
            <!--phase>process-classes</phase-->
            <goals>
              <goal>check</goal>
            </goals>
            <configuration>
              <includeJavaHome>false</includeJavaHome>
              <signature>
                <groupId>com.googlecode.jinahya</groupId>
                <artifactId>android-api-signature-10</artifactId>
                <version>1.0</version>
              </signature>
            </configuration>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
</project>

building android 2.3.3


references


frameworks/base/libs/utils/Android.mk

#LOCAL_CFLAGS += -DLIBUTILS_NATIVE=1 $(TOOL_CFLAGS)
LOCAL_CFLAGS += -DLIBUTILS_NATIVE=1 $(TOOL_CFLAGS) -fpermissive

build/core/combo/HOST_linux-x86.mk

#HOST_GLOBAL_CFLAGS += -D_FORTIFY_SOURCE=0
HOST_GLOBAL_CFLAGS += -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=0

JAVA_HOME

$ echo $JAVA_HOME
/usr/lib/jvm/java-6-oracle
$

gcc/g++

$ gcc -v
Using built-in specs.
Target: x86_64-linux-gnu
Configured with: ...
Thread model: posix
gcc version 4.4.7 (Ubuntu/Linaro 4.4.7-1ubuntu2) 
$ g++ -v
Using built-in specs.
Target: x86_64-linux-gnu
Configured with: ...
Thread model: posix
gcc version 4.4.7 (Ubuntu/Linaro 4.4.7-1ubuntu2)
$