anolivetree / gradle-clojure-android-sample

2 stars 1 forks source link

Build clojure 1.7 : clojure.lang.DalvikDynamicClassLoader error #2

Closed xlisp closed 4 years ago

xlisp commented 6 years ago

Hi, Hiroshi Sakurai,

I want run clojure in my Android clojure project, This is my project : https://github.com/chanshunli/termux-app .

but start error.


04-26 16:22:35.573  5589  5589 E AndroidRuntime: Process: com.termux, PID: 5589
04-26 16:22:35.573  5589  5589 E AndroidRuntime: java.lang.ExceptionInInitializerError
04-26 16:22:35.573  5589  5589 E AndroidRuntime:    at clojure.lang.RT.var(RT.java:351)
04-26 16:22:35.573  5589  5589 E AndroidRuntime:    at clojure.lang.DalvikDynamicClassLoader.<clinit>(DalvikDynamicClassLoader.java:38)
04-26 16:22:35.573  5589  5589 E AndroidRuntime:    at java.lang.Class.classForName(Native Method)
04-26 16:22:35.573  5589  5589 E AndroidRuntime:    at java.lang.Class.forName(Class.java:400)
04-26 16:22:35.573  5589  5589 E AndroidRuntime:    at java.lang.Class.forName(Class.java:326)
04-26 16:22:35.573  5589  5589 E AndroidRuntime:    at com.termux.app.TermuxService.onCreate(TermuxService.java:177)
04-26 16:22:35.573  5589  5589 E AndroidRuntime:    at android.app.ActivityThread.handleCreateService(ActivityThread.java:3162)
04-26 16:22:35.573  5589  5589 E AndroidRuntime:    at android.app.ActivityThread.-wrap5(ActivityThread.java)
04-26 16:22:35.573  5589  5589 E AndroidRuntime:    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1550)
04-26 16:22:35.573  5589  5589 E AndroidRuntime:    at android.os.Handler.dispatchMessage(Handler.java:102)
04-26 16:22:35.573  5589  5589 E AndroidRuntime:    at android.os.Looper.loop(Looper.java:154)
04-26 16:22:35.573  5589  5589 E AndroidRuntime:    at android.app.ActivityThread.main(ActivityThread.java:6077)
04-26 16:22:35.573  5589  5589 E AndroidRuntime:    at java.lang.reflect.Method.invoke(Native Method)
04-26 16:22:35.573  5589  5589 E AndroidRuntime:    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865)
04-26 16:22:35.573  5589  5589 E AndroidRuntime:    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)
04-26 16:22:35.573  5589  5589 E AndroidRuntime: Caused by: java.io.FileNotFoundException: Could not locate clojure/core__init.class or clojure/core.clj on classpath.
04-26 16:22:35.573  5589  5589 E AndroidRuntime:    at clojure.lang.RT.load(RT.java:462)
04-26 16:22:35.573  5589  5589 E AndroidRuntime:    at clojure.lang.RT.load(RT.java:421)
04-26 16:22:35.573  5589  5589 E AndroidRuntime:    at clojure.lang.RT.doInit(RT.java:469)
04-26 16:22:35.573  5589  5589 E AndroidRuntime:    at clojure.lang.RT.<clinit>(RT.java:339)
04-26 16:22:35.573  5589  5589 E AndroidRuntime:    ... 15 more
04-26 16:22:35.575   540  1114 W ActivityManager:   Force finishing activity com.termux/.app.TermuxActivity

thanks :-)

anolivetree commented 6 years ago

I have no idea why it doesn't work. It seems clojure's core is not AOT compiled, or not included in apk.

Does the sample project compiles and works for you? https://github.com/anolivetree/gradle-clojure-android-sample

xlisp commented 6 years ago

Thanks for your reply. Yes, your project anolivetree/gradle-clojure-android-sample help me, but not success for this project https://github.com/chanshunli/termux-app .

➜ termux-app git:(master) find . -name build.gradle ./app/build.gradle ./build.gradle ./terminal-view/build.gradle ./terminal-emulator/build.gradle

➜ termux-app git:(master) cat settings.gradle include ':app', ':terminal-emulator', ':terminal-view'


* [DalvikDynamicClassLoader run in MyApp](https://github.com/chanshunli/termux-app/blob/master/app/src/main/java/com/termux/app/MyApp.java)

```java

// ➜  termux-app git:(master) cat ./app/src/main/java/com/termux/app/MyApp.java

package com.termux.app;

import android.app.Application;
import android.content.Context;
import android.util.Log;

import java.lang.reflect.Method;

import clojure.lang.IFn;
import clojure.lang.RT;

public class MyApp extends Application {

    static public final String TAG = "clojure";

    @Override
    public void onCreate() {
        super.onCreate();

        try {
            Class dalvikCLclass = Class.forName("clojure.lang.DalvikDynamicClassLoader");
            Method setContext = dalvikCLclass.getMethod("setContext", Context.class);
            setContext.invoke(null, this);
        } catch (ClassNotFoundException e) {
            Log.i(TAG, "DalvikDynamicClassLoader is not found, probably Skummet is used.");
        } catch (Exception e) {
            Log.e(TAG, "setContext method not found, check if your Clojure dependency is correct.");
        }

    }

}
xlisp commented 6 years ago

I don't konw how to add "clojure aot task " for ./terminal-view/build.gradle & ./terminal-emulator/build.gradle

clojure {
    aotCompile = true
}

plugins {
    id "com.jfrog.bintray" version "1.7.3"
    id "com.github.dcendents.android-maven" version "2.0"
}

apply plugin: 'com.android.library'

ext {
    bintrayName = 'terminal-view'
    publishedGroupId = 'com.termux'
    libraryName = 'TerminalView'
    artifact = 'terminal-view'
    libraryDescription = 'The terminal view used in Termux'
    siteUrl = 'https://github.com/termux/termux'
    gitUrl = 'https://github.com/termux/termux.git'
    libraryVersion = '0.50'
}

android {
    compileSdkVersion 27

    dependencies {
        implementation 'com.android.support:support-annotations:27.1.0'
        api project(":terminal-emulator")
    }

    defaultConfig {
        minSdkVersion 21
        targetSdkVersion 27
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    testImplementation 'junit:junit:4.12'
}

apply from: '../scripts/bintray-publish.gradle'

plugins {
    id "com.jfrog.bintray" version "1.7.3"
    id "com.github.dcendents.android-maven" version "2.0"
}

apply plugin: 'com.android.library'

ext {
    bintrayName = 'terminal-emulator'
    publishedGroupId = 'com.termux'
    libraryName = 'TerminalEmulator'
    artifact = 'terminal-emulator'
    libraryDescription = 'The terminal emulator used in Termux'
    siteUrl = 'https://github.com/termux/termux'
    gitUrl = 'https://github.com/termux/termux.git'
    libraryVersion = '0.52'
}

android {
    compileSdkVersion 27

    defaultConfig {
        minSdkVersion 21
        targetSdkVersion 27

        externalNativeBuild {
            ndkBuild {
                cFlags "-std=c11", "-Wall", "-Wextra", "-Werror", "-Os", "-fno-stack-protector", "-Wl,--gc-sections"
            }
        }

        ndk {
            abiFilters 'x86', 'x86_64', 'armeabi-v7a', 'arm64-v8a'
        }
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

    externalNativeBuild {
        ndkBuild {
            path "src/main/jni/Android.mk"
        }
    }
}

tasks.withType(Test) {
    testLogging {
        events "started", "passed", "skipped", "failed"
    }
}

dependencies {
    testImplementation 'junit:junit:4.12'
}

apply from: '../scripts/bintray-publish.gradle'

Thanks for your help.