我想在Android上使用apache Flink Gradle依赖项,我几天都在努力解决这个问题,所以基本上我已经
multidex disabled
g8 enabled
jacktoolchain disabled
在我的dex
文件中,包含了apache Flink库,如下所示
但是当我运行程序时出现以下错误
java.lang.NoClassDefFoundError: Failed resolution of: Lorg/apache/flink/streaming/api/environment/StreamExecutionEnvironment;
at com.example.amar.testing.MainActivity.onCreate(MainActivity.java:23)
at android.app.Activity.performCreate(Activity.java:6999)
at android.app.Activity.performCreate(Activity.java:6990)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1214)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2731)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2856)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1589)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6494)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
Caused by: java.lang.ClassNotFoundException: Didn't find class "org.apache.flink.streaming.api.environment.StreamExecutionEnvironment" on path: DexPathList[[zip file "/data/app/com.example.amar.testing-ryJ3lLP7oEIkB8lomG6tmA==/base.apk"],nativeLibraryDirectories=[/data/app/com.example.amar.testing-ryJ3lLP7oEIkB8lomG6tmA==/lib/x86, /system/lib, /vendor/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:125)
at ja...
应用级build.gradle
文件的内容为
apply plugin: 'com.android.application'
repositories {
mavenCentral()
jcenter()
}
configurations {
compileOnly
}
android {
packagingOptions {
exclude 'META-INF/DEPENDENCIES.txt'
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/dependencies.txt'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/LICENSE'
exclude 'META-INF/license.txt'
exclude 'META-INF/LGPL2.1'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/NOTICE'
exclude 'META-INF/notice.txt'
}
configurations.all {
// Enforces Gradle to only compile the version number you state for all dependencies, no matter which version number the dependencies have stated.
resolutionStrategy.force 'com.google.code.findbugs:jsr305:1.3.9'
}
compileSdkVersion 26
buildToolsVersion '26.0.2'
defaultConfig {
// multiDexEnabled true
applicationId "com.example.amar.testing"
minSdkVersion 26
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
customDebugType {
debuggable true
}
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
// dexOptions {
// preDexLibraries = false
// }
}
dependencies {
// not sure if adding compatibility is required here
// sourceCompatibility = 1.7
// targetCompatibility = 1.7
androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compileOnly 'org.apache.flink:flink-streaming-java_2.11:1.4.0'
// for multidex
// implementation 'com.android.support:multidex:1.0.0'
// for CEP
// compile group: 'org.apache.flink', name: 'flink-java', version: '1.4.0'
implementation 'com.android.support:appcompat-v7:26.+'
implementation 'com.android.support.constraint:constraint-layout:1.0.0-alpha7'
implementation 'com.android.support:design:26.+'
testImplementation 'junit:junit:4.12'
}
项目级build.gradle
文件的内容是
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.0'
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
sourceCompatibility = 1.8
targetCompatibility = 1.8
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
google()
}
}
我主要活动的代码是
package com.example.amar.testing;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import org.apache.flink.streaming.api.datastream.DataStream;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// MultiDex.install(this);
try {
//setting the envrionment variable as StreamExecutionEnvironment
StreamExecutionEnvironment envrionment = StreamExecutionEnvironment.getExecutionEnvironment();
envrionment.setParallelism(1);
DataStream<Event> stream1 = envrionment
.addSource(new EventGenerator(10, 10, 1, 1, 100, 200))
.name("stream 1")
.setParallelism(1);
envrionment.execute();
} catch (Exception e) {
String err = e.getMessage();
Log.d("E", err);
}
} //onClick
}