Access methods from .jar file in react native - android

I am trying to connect postek EM 210 Bluetooth printer using my react native mobile app. I have SDK/ .jar file but need help for implementing its methods in react native
Postek has provided android SDK for use in android studio. Since my project is in react-native, I have included the .jar file in my project but have no clue how to use this file in react-native and access methods and functions that are available inside .jar file.
package com.postek.coyote.cdfptkbluetooth;
..
..
import com.postek.cdf.CDFPTKAndroid;
import com.postek.cdf.CDFPTKAndroidImpl;
public class BluetoothActivity extends AppCompatActivity implements AdapterView.OnItemClickListener, AdapterView.OnItemLongClickListener {
...
public static CDFPTKAndroid cdf = null;
...
}
So how do I convert these lines to react-native -
import com.postek.cdf.CDFPTKAndroid;
import com.postek.cdf.CDFPTKAndroidImpl;
..
public static CDFPTKAndroid cdf = null;
Alternatively, I want develop same app (using same SDK) with Bluetooth as here but in react-native.
Side note - We will even make react-native version of this app available on git for other developer who may be looking for this.

Related

Implementation of Compiled code is hidden Kotlin Android

I've been trying to write a library in kotlin and once the library build is generated as aar file when opening it in Android Studio it is not showing me how my class exactly looks and how the methods are implemented in that.
// IntelliJ API Decompiler stub source generated from a class file
// Implementation of methods is not available
package com.mypackage.dexter
public final class Test private constructor() {
public final fun testMethod(): kotlin.Unit { /* compiled code */ }
}
I've tried Java decompiler plugin in android studio, Kotlin Byte code (This also doesn't show it in the same format that we get if the same code is written in Java). The ultimate thing that I wanted to achieve by looking at the code is that I want to use debugger in the library and evaluate things while running my application where this library is integrated.

Run UiAutomator API from Android Studio (v0.8)

When I work with tests - I add class in special module and run test configuration. Class extend (for example) TestCase and work well.
But when I extend UiAutomatorTestCase - I get error
java.lang.RuntimeException: Stub!
at com.android.uiautomator.testrunner.UiAutomatorTestCase.<init> (UiAutomatorTestCase.java:5) ...
My simple class:
import com.android.uiautomator.core.UiObjectNotFoundException;
import com.android.uiautomator.testrunner.UiAutomatorTestCase;
public class AutoTest extends UiAutomatorTestCase {
public void testSome() throws UiObjectNotFoundException {
getUiDevice().pressHome();
}
}
How to run it in Android Studio IDE?
Well, if you'd be interested in giving it another try....I was able to get a UIAutomator project started in Android Studio with the following [Github project] (https://github.com/wiliamsouza/bluetooth)
Clone the project locally.
Edit the gradle.properties file to point to your sdk, target and build tools
Import into Android Studio, if prompted be sure to select Gradle.
The accompanying [blog post] (http://wiliamsouza.github.io/#/2013/10/30/android-uiautomator-gradle-build-system) has more details.
I modified with my own test cases and is working well.

How to setup alljoyn sdk in android?

I am trying to setup two android devices to communicate with each other through wifi. Some of the links I have gone through suggest alljoyn sdk in order to accomplish this.
There is an sdk download but there is no documentation for how to setup environment.
Here is how to set up an AllJoyn SDK development environment with android studio:
Download the SDK from this page. Go for Android Core SDK - release (or debug).
Create a new blank android project.
Create directory <project>/app/src/main/jniLibs and <project>/app/src/main/jniLibs/armeabi.
From alljoyn-15.09.00-rel/java/jar copy alljoyn.jar and from alljoyn-15.09.00-rel/java/lib copy liballjoyn_java.so. The directory to copy from might differ depending on the current version and your release/debug choice.
Put alljoyn.jar in /jniLibs and put liballjoyn_java.so in /jniLibs/armeabi. Should look like this
Right click project -> Open Module Settings -> app -> Dependencies.
With the green [+] button, add a file dependency.
Navigate to <project>/app/src/main/jniLibs/alljoyn.jar and select that jar.
This will add a line in your gradle (compile files('src/main/jniLibs/alljoyn.jar')) that will allow for code completion etc.
In the file where you want to use alljoyn code, include this snippet
/* Load the native alljoyn_java library. */
static {
System.loadLibrary("alljoyn_java");
}
for example:
public class MainActivity extends AppCompatActivity {
/* Load the native alljoyn_java library. */
static {
System.loadLibrary("alljoyn_java");
}
#Override
public void onCreate(Bundle savedInstanceState) {
...
}
}
You can now use the alljoyn SDK. Import classes with
import org.alljoyn.bus.BusAttachment;
import org.alljoyn.bus.BusException;
import org.alljoyn.bus.BusListener;
etc.
If you're more of an eclipse guy, check this official documentation page on how to setup an eclipse environment.

AndroidWebDriver class missing in Selenium-Java library

I tried a example provided in the, Android app testing through Selenium, i have included the selenium-java library and android-webdriver apk also installed in emulator, but when try with the sample code provide in the forum i got error in AnroidWebDriver import, in selenium library only AndroidDriver class is available, so where could i get the AdroidWebDriver jar. Plz assit.
Note: Selenium library is very latest one.
import android.test.ActivityInstrumentationTestCase2;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.android.AndroidWebDriver;
import simple.app.SimpleAppActivity;
public class SimpleGoogleTest extends ActivityInstrumentationTestCase2<SimpleAppActivity> {
private WebDriver driver;
private WebDriver googledriver;
public SimpleGoogleTest() {
super("simple.app", SimpleAppActivity.class);
}
#Override
protected void setUp() throws Exception {
driver = new AndroidWebDriver(getActivity());
}
........................,,,,,
}
There are two variations of the Android Driver:
AndroidDriver() which you use on your Personal Computer e.g. your
laptop, workstation, etc. which provides the richest and most
complete set of capabilities for your tests.
AndroidWebDriver() which runs on your Android device, this wraps a WebView component to provide the basic core functionality.
The example code that comes with the Android SDK and the optional support for Selenium/WebDriver runs some basic tests on the device. The tests are compiled as an Android program which extend ActivityInstrumentationTestCase2. AndroidWebDriver() is contained in sdk/extras/google/webdriver/android_webdriver_library.jar (and the Javadocs are in sdk/extras/google/webdriver/android_webdriver_library-srcs.jar
So, if you want to run your tests on your Android device, then you need to include android-webdriver-library.jar in your project. Perhaps the simplest way is to copy this jar into your test project's libs folder.
However, if you would like to run your tests on your Personal Computer you can modify the example code to use AndroidDriver instead of AndroidWebDriver. You also need to change your base class e.g. to use Junit 3 or Junit 4. I have posted a sample test as an answer to another question on Stack Overflow here Having difficulty in finding Elements using Xpath and CSS in Selenium Android Webdriver Testing

log4j support in Android

I am attempting to shoehorn an existing SDK onto an android device and one of the dependencies of said SDK is Apache log4j. I am able to load my test program onto the android emulator but when the log4j object "PropertySetter" is called the program fails with a verification exception. Is there a way to ameliorate this issue?
Actually using slf4j turned out a remarkably painless process for me, and it seems the common case, at least for libraries that use straightforward log4j features. You don't really need to swap slf4j in for log4j, only add two slf4j libraries to your project from http://www.slf4j.org/download.html:
-- the slf4j library for Android (currently slf4j-android-1.6.1-RC1.jar)
-- the log4j over slf4j (http://www.slf4j.org/legacy.html#log4j-over-slf4j) bridge.
The latter defines the core log4j classes used by typical implementations and bind them to the slf4j Android implementation. Once the libraries are added the code works.
I successfully got log4j working on android with a Socket Appender and Log4j Chainsaw. All code is located in this repository. Slf4j set up and working too. Be aware you have to configure it programmatically. You cannot use .properties or .xml files the parser wont work on android. Enjoy.
https://sourceforge.net/projects/log4j-android/
There is a new project, which enables log4j on android. Also using log4j over slf4j is possible. It also provides an appender for LogCat. See Logging in Android using Log4J.
The following example shows how to configure and use log4j in Android.
Configure the log4j system in Android
import org.apache.log4j.Level;
import android.os.Environment;
import de.mindpipe.android.logging.log4j.LogConfigurator;
/**
* Simply place a class like this in your Android applications classpath.
*/
public class ConfigureLog4J {
static {
final LogConfigurator logConfigurator = new LogConfigurator();
logConfigurator.setFileName(Environment.getExternalStorageDirectory() + "myapp.log");
logConfigurator.setRootLevel(Level.DEBUG);
// Set log level of a specific logger
logConfigurator.setLevel("org.apache", Level.ERROR);
logConfigurator.configure();
}
}
Logging in Android using log4j using slf4j API
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class ExampleLog4JOverSLF4J {
private final Logger log = LoggerFactory.getLogger(ExampleLog4JOverSLF4J.class);
public void myMethod() {
log.info("This message should be seen in log file and logcat");
}
}
Logging in Android using log4j API
import org.apache.log4j.Logger;
public class ExampleLog4J {
private final Logger log = Logger.getLogger(LogConfiguratorTest.class);
public void myMethod() {
log.info("This message should be seen in log file and logcat");
}
}
I would recommend trying to swap in slf4j in place of log4j. It's not a painless switch but its likely to be easier than what you have. slf4j provides a common front-end for several loggers including log4j and there is an slf4j-android package.
No, Android's logging mechanism is not decent. It's very inadequate compared to what log4j can do for you.
The parser for log4j configuration files is not android safe.slf4j's android compatibility thing with log4j just overrides the log4j classes you will use and forces them to use android logcat style logging. You still don't get the full flexibility of log4j on android. I ported log4j on android in my project https://sourceforge.net/projects/log4j-android/ all you have to do is add the two jars in the binaries directory to you classpath. Then
static {
org.apache.log4j.Logger root = org.apache.log4j.Logger.getRootLogger();
final SocketAppender appender = new SocketAppender("192.168.1.4", 4445);
root.addAppender(appender);
}
private static final org.slf4j.Logger logger = LoggerFactory.getLogger(MyClass.class);
static {
logger.info("Hello logger");
}
This will start sending out messages to the remote host you specified. You can then see this messages with Chainsaw http://logging.apache.org/log4j/docs/webstart/chainsaw/chainsawWebStart.jnlp. To make chainsaw work click the second check box on the dialog that pops up hit ok, start your app and a new tab should appear. Be aware your firewall might block it...
Check out this project for a complete implementation: http://code.google.com/p/log4j-android/

Categories

Resources