juicycleff / flutter-unity-view-widget

Embeddable unity game engine view for Flutter. Advance demo here https://github.com/juicycleff/flutter-unity-arkit-demo
BSD 3-Clause "New" or "Revised" License
2.13k stars 518 forks source link

UnityPlayerActivity.java:3: error: package android.app does not exist #855

Closed larsien closed 1 year ago

larsien commented 1 year ago

Describe the bug

UnityPlayerActivity.java:3: error: package android.app does not exist
UnityPlayerActivity.java:4: error: package android.content does not exist
UnityPlayerActivity.java:5: error: package android.content.res does not exist
UnityPlayerActivity.java:6: error: package android.graphics does not exist
....
UnityPlayerActivity.java:163: error: method does not override or implement a method from a supertype
    @Override public boolean onGenericMotionEvent(MotionEvent event)  { return mUnityPlayer.onGenericMotionEvent(event); }
    ^
Note: Some messages have been simplified; recompile with -Xdiags:verbose to get full output
62 errors

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':unityLibrary:compileDebugJavaWithJavac'.
> Compilation failed; see the compiler error output for details.

on 'flutter run' in Android Studio

build on Linux

To Reproduce Follow steps on here: https://pub.dev/packages/flutter_unity_widget#steps

Expected behavior Start the app.

Unity (please complete the following information):

Smartphone (please complete the following information):

Additional context flutter version is 3.0.0 and I have followed until "optional manual android setup No6". I have checked my

And read https://github.com/juicycleff/flutter-unity-view-widget/issues/662 . but it doesn't help.

My build.gradle files

  1. app/build.gradle
    
    apply plugin: 'com.android.application'
    apply plugin: 'com.chaquo.python'

def localProperties = new Properties() def localPropertiesFile = rootProject.file('local.properties') if (localPropertiesFile.exists()) { localPropertiesFile.withReader('UTF-8') { reader -> localProperties.load(reader) } }

def flutterRoot = localProperties.getProperty('flutter.sdk') if (flutterRoot == null) { throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.") }

def flutterVersionCode = localProperties.getProperty('flutter.versionCode') if (flutterVersionCode == null) { flutterVersionCode = '1' }

def flutterVersionName = localProperties.getProperty('flutter.versionName') if (flutterVersionName == null) { flutterVersionName = '1.0' }

apply plugin: 'com.android.application' apply plugin: 'kotlin-android' apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"

android { compileSdkVersion 33 ndkVersion '23.1.7779620'

sourceSets {
    main.java.srcDirs += 'src/main/kotlin'
}

defaultConfig {
    // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
    applicationId "com.easy_sidemenu.example"
    minSdkVersion 24
    targetSdkVersion 33
    versionCode flutterVersionCode.toInteger()
    versionName flutterVersionName
    multiDexEnabled true
    ndk {
        abiFilters "armeabi-v7a", "arm64-v8a", "x86", "x86_64"
    }
    python {
        pip {
            install "numpy"
            install "brainflow"
        }
    }
}

buildTypes {
    release {
        // TODO: Add your own signing config for the release build.
        // Signing with the debug keys for now, so `flutter run --release` works.
        signingConfig signingConfigs.debug
        shrinkResources false
        minifyEnabled false
    }
}

}

flutter { source '../..' }

dependencies { implementation project(':unityLibrary') implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" }

2. android/build.gradle 

buildscript { ext.kotlin_version = '1.6.10' repositories { google() jcenter() maven { url "https://chaquo.com/maven" } }

dependencies {
    classpath 'com.android.tools.build:gradle:4.1.0'
    classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    classpath "com.chaquo.python:gradle:14.0.2"
}

}

allprojects { repositories { flatDir { dirs "${project(':unityLibrary').projectDir}/libs" }

    google()
    jcenter()
}

}

rootProject.buildDir = '../build' subprojects { project.buildDir = "${rootProject.buildDir}/${project.name}" project.evaluationDependsOn(':app') }

task clean(type: Delete) { delete rootProject.buildDir }

3. unityLibrary/build.gradle

apply plugin: 'com.android.library'

dependencies { implementation(name: 'unity-classes', ext:'jar') implementation(name: 'arcore_client', ext:'aar') implementation(name: 'ARPresto', ext:'aar') implementation(name: 'UnityARCore', ext:'aar') implementation(name: 'unityandroidpermissions', ext:'aar')

}

android { ndkPath "/home/ksh/Unity/Hub/Editor/2022.2.0f1/Editor/Data/PlaybackEngines/AndroidPlayer/NDK"

compileSdkVersion 33
buildToolsVersion '32.0.0'

compileOptions {
    sourceCompatibility JavaVersion.VERSION_11
    targetCompatibility JavaVersion.VERSION_11
}

defaultConfig {
    minSdkVersion 24
    targetSdkVersion 33
    ndk {
        abiFilters 'armeabi-v7a', 'arm64-v8a'
    }
    versionCode 1
    versionName '1'
    consumerProguardFiles 'proguard-unity.txt'
}

lintOptions {
    abortOnError false
}

aaptOptions {
    noCompress = ['.unity3d', '.ress', '.resource', '.obb', '.bundle', '.unityexp']
    ignoreAssetsPattern = "!.svn:!.git:!.ds_store:!*.scc:!CVS:!thumbs.db:!picasa.ini:!*~"
}

packagingOptions {
    doNotStrip '*/armeabi-v7a/*.so'
    doNotStrip '*/arm64-v8a/*.so'
}

}

def getSdkDir() { Properties local = new Properties() local.load(new FileInputStream("${rootDir}/local.properties")) return local.getProperty('sdk.dir') }

def BuildIl2Cpp(String workingDir, String configuration, String architecture, String abi, String[] staticLibraries) { def commandLineArgs = [] commandLineArgs.add("--compile-cpp") commandLineArgs.add("--platform=Android") commandLineArgs.add("--architecture=" + architecture) commandLineArgs.add("--outputpath=" + workingDir + "/src/main/jniLibs/" + abi + "/libil2cpp.so") commandLineArgs.add("--libil2cpp-static") commandLineArgs.add("--baselib-directory=" + workingDir + "/src/main/jniStaticLibs/" + abi) commandLineArgs.add("--incremental-g-c-time-slice=3") commandLineArgs.add("--dotnetprofile=unityaot-linux") commandLineArgs.add("--enable-debugger") commandLineArgs.add("--profiler-report") commandLineArgs.add("--profiler-output-file=" + workingDir + "/build/il2cpp"+ abi + "" + configuration + "/il2cppconv.traceevents") commandLineArgs.add("--print-command-line") commandLineArgs.add("--data-folder=" + workingDir + "/src/main/Il2CppOutputProject/Source/il2cppOutput/data") commandLineArgs.add("--generatedcppdir=" + workingDir + "/src/main/Il2CppOutputProject/Source/il2cppOutput") commandLineArgs.add("--cachedirectory=" + workingDir + "/build/il2cpp"+ abi + "_" + configuration + "/il2cpp_cache") commandLineArgs.add("--tool-chain-path=" + android.ndkDirectory) staticLibraries.eachWithIndex {fileName, i-> commandLineArgs.add("--additional-libraries=" + workingDir + "/src/main/jniStaticLibs/" + abi + "/" + fileName) } def executableExtension = "" if (org.gradle.internal.os.OperatingSystem.current().isWindows()) executableExtension = ".exe" exec { executable workingDir + "/src/main/Il2CppOutputProject/IL2CPP/build/deploy/il2cpp" + executableExtension args commandLineArgs environment "ANDROID_SDK_ROOT", getSdkDir() } delete workingDir + "/src/main/jniLibs/" + abi + "/libil2cpp.sym.so" ant.move(file: workingDir + "/src/main/jniLibs/" + abi + "/libil2cpp.dbg.so", tofile: workingDir + "/symbols/" + abi + "/libil2cpp.so") }

android { task BuildIl2CppTask { doLast { BuildIl2Cpp(projectDir.toString().replaceAll('\\', '/'), 'Debug', 'armv7', 'armeabi-v7a', [ ] as String[]); BuildIl2Cpp(projectDir.toString().replaceAll('\\', '/'), 'Debug', 'arm64', 'arm64-v8a', [ ] as String[]); } } afterEvaluate { if (project(':unityLibrary').tasks.findByName('mergeDebugJniLibFolders')) project(':unityLibrary').mergeDebugJniLibFolders.dependsOn BuildIl2CppTask if (project(':unityLibrary').tasks.findByName('mergeReleaseJniLibFolders')) project(':unityLibrary').mergeReleaseJniLibFolders.dependsOn BuildIl2CppTask } sourceSets { main { jni.srcDirs = ["src/main/Il2CppOutputProject"] } } }

larsien commented 1 year ago

My environment is ubuntu Linux 22 finally i found an answer from Discord.

I removed flutter sdk with snap and I manually installed SDK. and finally it succeded