I'm trying to develop apps for EPSON Moverio BT-2000.
I'm new to android studio and I don't understand why I can't use some methods from a library which I have imported (correctly, I supposed).
So, I have add my lib in a folder name libs, right click on it, add as Library.
I checked in builds.gradle
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile files('libs/H725Ctrl.jar') // this lib
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:21.0.3'
}
Moreover, I can use some elements (Methods, String definitions etc..) but some not. I don't understand why and how it's possible.
If it's necessary I can publish my source code.
Have you some ideas.?
Thanks.
Franck
NB: the lib I use is depreciated by android
NB2: Exemple
Camera.Parameters params = l_pCamera.getParameters();
// I can do this and getParameters() works
List<String> Supported = params.getSupportedEpsonCameraModes();
//I can't invoke getSupportedEpsonCameraModes() or methods are in the same file
I contacted EPSON and they said it's a common problem.
So they send me a pdf which indicate how solve the problem..
It's strange..
NB the content of the PDF: sorry for the presentation but it will be helpful for someone..
1/2
Remark for using Android Studio
In case of using BT-2000 SDK with Android Studio, there may happen to have a failure during a build process. It may cause the conflict of the name between standard SDK and Epson expanded SDK. It is happened especially with “android.hardware.Camera” class.
It may resolve a failure with following action.
1. Sore H725Ctrl.jar at designated folder which is created by user like C:\Users\<user name\AndroidStudioProjects\<application name>\app\libs
2. Set change of gradle by selecting “Sync Project with Gradle Files” button which is located upper of Android Studio screen.
3. Open “build.gradle” for specified project with specified application name by selecting left side button on Android Studio screen. Then edit with following contents.
allprojects { repositories { jcenter() } gradle.projectsEvaluated { tasks.withType(JavaCompile) { options.compilerArgs.add('-Xbootclasspath/p:C:/Users/<user name>/AndroidStudioProjects/<application name>/app/libs/H725Ctrl.jar') } } }
4. Execute “Clean Project” then “Make Project” in Android Studio Build menu.
5. If error occurs in Make project process, end Android Studio and restart it.
2/2
6. There may still remain several name conflicts with Android standard API like “getSupportedEpsonCameraModes()”. Ignore and “run application” to set it into target BT-2000.
[ Caution ]
It works temporally with following action;
Open
C:\Users\<user name>\AndroidStudioProjects\<application name>\app\app.iml
Move line of
<orderEntry type="library" exported="" name="H725Ctrl" level="project" />
to upper line of
<orderEntry type="jdk" jdkName="Android API 23 Platform" jdkType="Android SDK" />
This will help H725Ctrl.jar to be higher priority, however performing rebuild function will affect to reset name conflict issue.
Object which is performed build function already works well.
It's weird. Epson tries to override some Android specific classes in their jar:
android.hardware.Camera
android.hardware.Camera.Parameters
These classes are part of the Android SDK (http://developer.android.com/reference/android/hardware/Camera.html). I do not know Epson would like to achieve, if they bundle the classes with their SDK. Maybe you could change the packagename in the H725Ctrl.jar to something like
com.epson.hardware
with JarJar (https://github.com/shevek/jarjar)?
Add the following code to your build.gradle file. The problem could be that the Moverio Camera class uses the same namespace as the Android sdk and there is an ordering issue
allprojects {
repositories {
jcenter()
}
gradle.projectsEvaluated {
tasks.withType(JavaCompile) {
options.compilerArgs.add('-Xbootclasspath/p:C:/Source/EPSONProBT-2000ServiceMaintenance/app/libs/H725Ctrl.jar')
}
}
}
Related
Background
Suppose I make an Android library called "MySdk", and I publish it on Jitpack/Maven.
The user of the SDK would use it by adding just the dependency of :
implementation 'com.github.my-sdk:MySdk:1.0.1'
What I'd like to get is the "1.0.1" part from it, whether I do it from within the Android library itself (can be useful to send to the SDK-server which version is used), or from the app that uses it (can be useful to report about specific issues, including via Crashlytics).
The problem
I can't find any reflection or gradle task to reach it.
What I've tried
Searching about it, if I indeed work on the Android library (that is used as a dependency), all I've found is that I can manage the version myself, via code.
Some said I could use BuildConfig of the package name of the library, but then it means that if I forget to update the code a moment before I publish the dependency, it will use the wrong value. Example of using this method:
plugins {
...
}
final def sdkVersion = "1.0.22"
android {
...
buildTypes {
release {
...
buildConfigField "String", "SDK_VERSION", "\"" + sdkVersion + "\""
}
debug {
buildConfigField "String", "SDK_VERSION", "\"" + sdkVersion + "-unreleased\""
}
}
Usage is just checking the value of BuildConfig.SDK_VERSION (after building).
Another possible solution is perhaps from gradle task inside the Android-library, that would be forced to be launched whenever you build the app that uses this library. However, I've failed to find how do it (found something here)
The question
Is it possible to query the dependency version from within the Android library of the dependency (and from the app that uses it, of course), so that I could use it during runtime?
Something automatic, that won't require me to update it before publishing ?
Maybe using Gradle task that is defined in the library, and forced to be used when building the app that uses the library?
You can use a Gradle task to capture the version of the library as presented in the build.gradle dependencies and store the version information in BuildConfig.java for each build type.
The task below captures the version of the "appcompat" dependency as an example.
dependencies {
implementation 'androidx.appcompat:appcompat:1.4.0'
}
task CaptureLibraryVersion {
def libDef = project.configurations.getByName('implementation').allDependencies.matching {
it.group.equals("androidx.appcompat") && it.name.equals("appcompat")
}
if (libDef.size() > 0) {
android.buildTypes.each {
it.buildConfigField 'String', 'LIB_VERSION', "\"${libDef[0].version}\""
}
}
}
For my example, the "appcompat" version was 1.4.0. After the task is run, BuildConfig.java contains
// Field from build type: debug
public static final String LIB_VERSION = "1.4.0";
You can reference this field in code with BuildConfig.LIB_VERSION. The task can be automatically run during each build cycle.
The simple answer to your question is 'yes' - you can do it. But if you want a simple solution to do it so the answer transforms to 'no' - there is no simple solution.
The libraries are in the classpath of your package, thus the only way to access their info at the runtime would be to record needed information during the compilation time and expose it to your application at the runtime.
There are two major 'correct' ways and you kinda have described them in your question but I will elaborate a bit.
The most correct way and relatively easy way is to expose all those variables as BuildConfig or String res values via gradle pretty much as described here. You can try to generify the approach for this using local-prefs(or helper gradle file) to store versions and use them everywhere it is needed. More info here, here, and here
The second correct, but much more complicated way is to write a gradle plugin or at least some set of tasks for collecting needed values during compile-time and providing an interface(usually via your app assets or res) for your app to access them during runtime. A pretty similar thing is already implemented for google libraries in Google Play services Plugins so it would be a good place to start.
All the other possible implementations are variations of the described two or their combination.
You can create buildSrc folder and manage dependencies in there.
after that, you can import & use Versions class in anywhere of your app.
What I'm trying to achieve
I'm trying to generate my REST API client for Android using OpenAPI Generator from the build.gradle script. That way, I wouldn't have to run the generator command line every time the specs change. Ideally, this would be generated when I build/assemble my app, and the sources would end up in the java (generated) folder, where generated sources are then accessible from the code (this is what happens with the BuildConfig.java file for example).
What I've tried so far
Following this link from their official GitHub, here's the build.gradle file I ended up with:
apply plugin: 'com.android.application'
apply plugin: 'org.openapi.generator'
...
openApiValidate {
inputSpec = "$rootDir/app/src/main/openapi/my-api.yaml"
recommend = true
}
openApiGenerate {
generatorName = "java"
inputSpec = "$rootDir/app/src/main/openapi/my-api.yaml"
outputDir = "$buildDir/generated/openapi"
groupId = "$project.group"
id = "$project.name-openapi"
version = "$project.version"
apiPackage = "com.example.mypackage.api"
invokerPackage = "com.example.mypackage.invoker"
modelPackage = "com.example.mypackage.model"
configOptions = [
java8 : "true",
dateLibrary : "java8",
library : "retrofit2"
]
}
...
First, I've never managed to get the API generated with the build/assemble task, even when I tried adding:
compileJava.dependsOn tasks.openApiGenerate
or
assemble.dependsOn tasks.openApiGenerate
The only way I could generate the sources was by manually triggering the openApiGenerate task:
Then, when I do generate my sources this way, they end up in the build folder but aren't accessible from my code, and aren't visible in the java (generated) folder:
I then have to manually copy/paste the generated source files to my project sources in order to use the API.
Even though I'm able to work around these issues by adding manual procedures, it would be way more maintainable if the whole process was simply automatic. I was able to achieve a similar result with another tool, Protobuf. Indeed, my gradle task gets triggered every time I build the app, and the sources end up in the java (generated) folder, so I don't have to do any additional work. The task is much simpler though, so I assume the main work that I'm not able to replicate with OpenAPI Generator is handled by the Protobuf plugin itself.
You have to specify path to the generated sources as a custom source set for your Gradle module, which is app in this case, as described here – https://developer.android.com/studio/build/build-variants#configure-sourcesets. That way Gradle will treat your sources as accessible from your code.
Something like this:
android {
...
sourceSets {
main {
java.srcDirs = ['build/generated/openapi/src/main/java']
}
}
...
}
I solved the issue you described like this, I'm using gradle.kts however.
See my build.gradle.kts
plugins {
// Your other plugins
id("org.openapi.generator") version "5.3.0"
}
openApiGenerate {
generatorName.set("kotlin")
inputSpec.set("$rootDir/app/src/main/openapi/my-api.yaml")
outputDir.set("$buildDir/generated/api")
// Your other specification
}
application {
// Your other code
sourceSets {
main {
java {
// TODO: Set this path according to what was generated for you
srcDir("$buildDir/generated/api/src/main/kotlin")
}
}
}
}
tasks.compileKotlin {
dependsOn(tasks.openApiGenerate)
}
You need to build the application at least once for the IDE to detect the library (at least this is the case for me in Intellij)
Your build should automatically generate the open api classes , to refer the generated classes in your java project you should add the generated class path to your source directory like it was mentioned in the other answers
https://developer.android.com/studio/build/build-variants#configure-sourcesets
As far as the task dependency goes , in android tasks are generated after configuration thus for gradle to recognize the task , wrap it inside afterEvaluate block like
afterEvaluate {
tasks.compileDebugJavaWithJavac.dependsOn(tasks.openApiGenerate)
}
I had this issue, and this answer https://stackoverflow.com/a/55646891/14111809 led me to a more informative error:
error: incompatible types: Object cannot be converted to Annotation
#java.lang.Object()
Taking a look at the generated files that were causing this error, noticed:
import com.squareup.moshi.Json;
After including a Moshi in the app build.gradle, the build succeeded and the generated code was accessible.
implementation("com.squareup.moshi:moshi-kotlin:1.13.0")
Unity has a default gradle.properties file that gets added during the build process. While its possible to change the build.gradle and the settings.gradle files as mentioned
here https://docs.unity3d.com/Manual/android-gradle-overview.html
there is no mention of being able to change gradle.properties within the unity docs. The file also gets recreated every build attempt so editing it within the temp/gradleOut after a build and building again doesn't work. I know exporting the project is possible as well, but I'm looking for a solution where the project can be run directly from unity.
Btw this question is NOT a duplicate of this question How to use Gradle in Unity
The answer here has nothing to do with modifying the gradle.properties file.
This is a duplicate of this question that got incorrectly marked as a duplicate how to change default gradle.properties of Unity?
Maybe my answer is a bit outdated but in Unity 2020 you can do it in:
Player Settings -> Tab Android (with robot obviously) -> Publishing Settings -> Custom Gradle Properties Template (checkbox).
After enabling the checkbox you will see the path to gradleTemplate.properties (usually it appears in Assets/Plugins/Android directory) file which will be merged with final gradle.properties.
Everything you need you can write to the end of file after **ADDITIONAL_PROPERTIES** string.
Example:
org.gradle.jvmargs=-Xmx**JVM_HEAP_SIZE**M
org.gradle.parallel=true
android.enableR8=**MINIFY_WITH_R_EIGHT**
**ADDITIONAL_PROPERTIES**
android.useAndroidX = true // I added this property to fix error: This project uses AndroidX dependencies, but the 'android.useAndroidX' property is not enabled. Set this property to true in the gradle.properties file and retry.
Also on screenshot:
This was something that was slightly hard to discover. I was going to do a regular post build processor like I had for my iOS build, but as I was searching for a manner to load and determine where the properties file was, I ran across the following interface in the documentation : IPostGenerateGradleAndroidProject.
According to the documentation:
Implement this interface to receive a callback after the Android
Gradle project is generated.
So below is my initial brute force implementation for turning on androidX and jetifier.
public class AndroidPostBuildProcessor : IPostGenerateGradleAndroidProject
{
public int callbackOrder
{
get
{
return 999;
}
}
void IPostGenerateGradleAndroidProject.OnPostGenerateGradleAndroidProject(string path)
{
Debug.Log("Bulid path : " + path);
string gradlePropertiesFile = path + "/gradle.properties";
if (File.Exists(gradlePropertiesFile))
{
File.Delete(gradlePropertiesFile);
}
StreamWriter writer = File.CreateText(gradlePropertiesFile);
writer.WriteLine("org.gradle.jvmargs=-Xmx4096M");
writer.WriteLine("android.useAndroidX=true");
writer.WriteLine("android.enableJetifier=true");
writer.Flush();
writer.Close();
}
}
Theoretically you should be able to manipulate the generated gradle project in any manner to your choosing during the post build processor. Some additional tools might be helpful, like the PBXProject support on iOS, but until then, this will do.
IPostGenerateGradleAndroidProject is a new Interface added after Unity2018.
As my project based on Unity2017, it's not a good solution. Then I found this. A solution with Gradle.
([rootProject] + (rootProject.subprojects as List)).each {
ext {
it.setProperty("android.useAndroidX", true)
it.setProperty("android.enableJetifier", true)
}
}
Although this is not a perfect solution, you can use the "Export Project" option.
Build Settings
After exporting the project, you can modify gradle.properties and build using AndroidStudio or command line.
In the newer Unity versions (2019.4+) it is possible to generate a custom gradle properties template by going to Project Settings > Player > (Android Tab) > Other Settings > and marking "Custom Gradle Properties Template".
After selecting that a gradleTemplate.properties file is generated at "Assets/Plugins/Android/gradleTemplate.properties".
This is the best way of generating the file since it is git friendly and preserves other settings.
Based on Android docs (https://developers.google.com/games/services/android/quickstart#before_you_begin) for learning how to configure Google Play game APIs onto a sample app such as TypeANumber, I was wondering why I get the following resource errors from the BaseGameUtils library after importing the project, BasicSamples, from their GitHub's (https://github.com/playgameservices/android-basic-samples) source files:
... Based on the directory in the left panel, did I import it properly? All I did was import it straight from the directory: android-basic-samples/BasicSamples/build.gradle as stated in Step 1 of the link.
Here's my (untouched) Gradle file for the library, BaseGameUtils:
apply plugin: 'com.android.library'
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.3.1'
}
}
dependencies {
// Set defaults so that BaseGameUtils can be used outside of BasicSamples
if (!project.hasProperty('appcompat_library_version')) {
ext.appcompat_library_version = '20.0.+'
}
if (!project.hasProperty('support_library_version')) {
ext.support_library_version = '20.0.+'
}
if (!project.hasProperty('gms_library_version')) {
ext.gms_library_version = '8.1.0'
}
compile "com.android.support:appcompat-v7:${appcompat_library_version}"
compile "com.android.support:support-v4:${support_library_version}"
compile "com.google.android.gms:play-services-games:${gms_library_version}"
compile "com.google.android.gms:play-services-plus:${gms_library_version}"
}
android {
// Set defaults so that BaseGameUtils can be used outside of BasicSamples
if (!project.hasProperty('android_compile_version')) {
ext.android_compile_version = 23
}
if (!project.hasProperty('android_version')) {
ext.android_version = '23'
}
compileSdkVersion android_compile_version
buildToolsVersion android_version
}
... Did anyone else experience this issue before?
EDIT AS OF 4/7, 3:37PM:
So I ended up importing the project again, but within the AndroidStudioProjects directory this time (does that really make a difference?) and I actually ended up making some progress since then. However, for part 3 under step 1 within the docs:
... I ended up changing not only the package name in TypeANumber's manifest file, but also the package directory along with the classes in it as follows:
... So my question now is, am I on the right track so far in terms of the navigation directory panel at the left? :)
Yes. The package attribute in the manifest should always match the directories. Plain and simple. That's why changing it would require you to do a complete refactor. Just keep on going with the tutorial accordingly and I think you'll be good.
How can I set the HTTP_ACCEPT_LANGUAGE header with CrossWalk?
I've tried looking for the same methods as the original Android webview (like described here: How can I override Android WebView to use custom Accept-Language header?) but no luck.
The normal webview sends the correct header, CrossWalk however doesn't include my native language, just 'en-US'.
I ended up editing the source, and then compiling from scratch.
If you want to do the same, the file to look in is "xwalk/runtime/browser/runtime_url_request_context_getter.cc"
Link to the file on Github
And then look for this:
storage_->set_http_user_agent_settings(
new net::StaticHttpUserAgentSettings("da-DK,da;q=0.8,en-US;q=0.6,en;q=0.4", base::EmptyString()));
In this we added the "da-DK,da;q=0.8", but you get the idea.
How to build Crosswalk from source
I had the same problem. I found out that the following beta version 15.44.384.8 accounts for this problem. So if you feel comfortable by using a beta version, you can find it here:
https://download.01.org/crosswalk/releases/crosswalk/android/maven2/org/xwalk/xwalk_core_library_beta/
When using version 15.44.384.8 crosswalk will automatically select the language of your device settings.
You can add this version by modifing you build.gradle as follows:
repositories {
maven {
url 'https://download.01.org/crosswalk/releases/crosswalk/android/maven2'
}
}
dependencies {
...other stuff...
compile 'org.xwalk:xwalk_core_library_beta:15.44.384.8'
}