Android Screenshot Plugin Working in Cordova 2.0 - java

I am currently developing an Android app using cordova 2.0. Obviously the plugins.xml has been depreciated and everything is now housed in config.xml. I was just wondering if anyone has managed to get the Phonegap Screenshot plugin working in Eclipse and Cordova 2.0 working on android.
Plugin can be found:
https://github.com/josemando/phonegap-plugins/tree/master/Android/Screenshot
I have added:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
to my Android manifest xml. And made sure that:
<plugin name="Screenshot" value="org.apache.cordova.Screenshot"/>
is added to my config.xml (that now contains all plugin information from plugin.xml)
Screenshot.js is added to the directory:
assets/www/js/
However I am unsure where exactly to place the Screenshot.java file. The example has it in:
src / org / apache / cordova /
However as I did not have this directory I simply placed it in:
src/uk.co..appname1.appname2/
When I did this however it produced errors, the first one being:
The declared package "org.apache.cordova" does not match the expected package "uk.co.mysitename.appname1.appname2" Screenshot.java /Project Name/src/uk/co/mysitename/appname1/appname2line 8 Java Problem
This refers to this line in the Screenshot.js:
package org.apache.cordova;
The two suggested actions to fix this are to:
Move 'Screenshot.java' to package 'org.apache.cordova' (this directory doesn't exsist atm)
Or change package directory to 'uk.co.mysitename.appname1.appname2'
The second error says:
The method run() of type new Runnable(){} must override a superclass method
The suggested action for this being to "remove '#override' annotation"
I have tried to do every possible combination of these however I cannot seem to make progress and get it all to link up. Usually because it thinks that CordovaRef isn't referenced. I am unsure if the plugin even works on Cordova 2.0.0. I have some experience with Phonegap/Cordova but only in ios with Xcode and Objective C plugins. I am new to Java, Eclipse and Android. Any help or clarification on any of these matters would be greatly appreciated.

Answer resolved by:
Phonegap Screenshot plugin in Cordova 2.0.0
Answer/solution provided by Simon MacDonald

Related

The plugin `firebase_auth` doesn't have a main class defined in C:\Users\

When adding firebase_auth to dependencies (pubspec.yaml) to my flutter project I'm getting this error:
The plugin firebase_auth doesn't have a main class defined in C:\Users(username)\AppData\Local\Pub\Cache\hosted\pub.dartlang.org\firebase_auth-3.1.3\android\src\main\java\io\flutter\plugins\firebase\auth\FlutterFirebaseAuthPlugin.java or C:\Users(username)\AppData\Local\Pub\Cache\hosted\pub.dartlang.org\firebase_auth-3.1.3\android\src\main\kotlin\io\flutter\plugins\firebase\auth\FlutterFirebaseAuthPlugin.kt. This is likely to due to an incorrect androidPackage: io.flutter.plugins.firebase.auth or mainClass entry in the plugin's pubspec.yaml.
If you are the author of this plugin, fix the androidPackage entry or move the main class to any of locations used above. Otherwise, please contact the author of this plugin and consider using a different plugin in the meanwhile.
My code is just the dummy code created by android studio and the only thing i added is firebase_auth: ^3.1.3 in pubsbec.yaml , the .json file in the android/app directory and registered the app on Firebase website.
I get the same issue in VS Code, so Android Studio is not the problem.
I would really appreciate any help!
Add the firebase_core pugin because it is essential and if you did everything according to the documentation then flutter clean after that pub cache repair will do the the work. then again run.
I think you haven't added Firebase core in your pubspec.yaml file. Try to add firebase_core 1.7.0 in your pubspec.yaml and then clean your project using this command flutter clean
also Checkout this installation guide

Missing Methods and Classes in Jar after Building Xamarin App

As i wanted to develop an App with Estimote Beacons i searched for it and found the Xamarin Component Estimote SDK for Android. However, the Version is outdated so i began to try including the estimote sdk for android on myself. With .aar/.jar Binding.
I saw three Options:
fully compile the library and be able to use it as C# Classes
write a wrapper and only let the wrapper interpret and use those classes.
natively call functions from the Library with JNI
Compiling the whole library did not work due to about 102 Errors while building. Working with metadata.xml did not work although i was able to reduce the amount of Errors to 45.
Natively calling functions with JNI is a pain and no option because the Library is too big.
Writing a wrapper nearly worked
I stripped the classes from the estimotesdk.aar so i have only the classes.jar from the inside.
Wrote a Library as wrapper and put that in another jar:
EstimoteSDK.jar --> ReferenceJar
EstimoteWrapper --> EmbeddedJar
I can build the ClassLibrary Project in Visual Studio without Problems. I can even use the classes from the Wrapper in C#.
But now my Problem is:
MissingMethodException and NoClassDefFoundError during Runtime
I found out the following:
The EstimoteSDK.jar and its Class-Files change after building .
For some reason, the EstimoteSDK.jar is not only copied but also modified and loses some functions and even classes.
Proof (used dex2jar tool to get the jar out of the .dex in the builded apk):
The right class File contains less functions than the right
Now my Question:
how can i prevent Xamarin or any other Component from touching the EstimoteSDK.jar and stripping functions and classes from it ?
Setup:
Visual Studio 2015 Professional
Xamarin.Forms 2.0
Windows 7
Android and iOS-App
So, after posting my question to xamarin forums where someone provided a updated version of estimotesdk ( i did not try that so far) and trying out everything i could imagine i found a solution for me:
I have two Jars (EstimoteSDK and my own written Wrapper). Including them with the correct Build Action did it for me:
EstimoteSDK.jar --> EmbeddedReferenceJar
List item --> EmbeddedJar
So this is the correct way to include a native library which is accessed by a wrapper class.
The magic word could be LinkerPleaseInclude.cs. Add a class that references the class / calls the function. But I don't know if your wrapper is in the way, because you aren't binding the estimote lib in the usual way.
public class LinkerPleaseInclude
{
public void Include(Beaconmanager manager)
{
manager.RegionExitExpiration = 0L;
}
}
btw: there is a crossplatform abstraction for estimote: https://www.nuget.org/packages/Estimotes.Xplat/. But it might use the outdated version you mentioned.
Edit:
metadata.xml for Estimote
<metadata>
<remove-node path="/api/package[#name='com.estimote.sdk.repackaged.okhttp_v2_2_0.com.squareup.okhttp.internal.http']"></remove-node>
<remove-node path="/api/package[#name='com.estimote.sdk.repackaged.gson_v2_3_1.com.google.gson.internal.bind']"></remove-node>
<remove-node path="/api/package[#name='com.estimote.sdk.repackaged.gson_v2_3_1.com.google.gson.internal']"></remove-node>
<remove-node path="/api/package[#name='com.estimote.sdk.repackaged.gson_v2_3_1.com.google.gson']"></remove-node>
<remove-node path="/api/package[#name='com.estimote.sdk.repackaged.okio_v1_3_0.okio']"></remove-node>
<remove-node path="/api/package[#name='com.estimote.sdk.repackaged.maven_v3_3_3']"></remove-node>
<remove-node path="/api/package[#name='com.estimote.sdk.connection.internal.protocols']"></remove-node>
<attr path="/api/package[#name='com.estimote.sdk.connection.settings']/class[#name='Version']/method[#name='compareTo' and count(parameter)=1 and parameter[1][#type='com.estimote.sdk.connection.settings.Version']]/parameter[1]"
name="type">Java.Lang.Object</attr>
<attr path="/api/package[#name='com.estimote.sdk.cloud.internal']/class[#name='ChallengeResponse']/field[#name='challengeResponse']" name="name">ChallangeResponseString</attr>
<attr path="/api/package[#name='com.estimote.sdk.cloud.model.google']/class[#name='Beacons']/field[#name='beacons']" name="name">BeaconList</attr>
<attr path="/api/package[#name='com.estimote.sdk.cloud.model.google']/class[#name='Observations']/field[#name='observations']" name="name">ObservationList</attr>
</metadata>

How to call a plugin method from another plugin in Eclipse?

I'm having the following situation:
I want to extend the functionality of a given plugin A (I have it's source code and start it by running the project as an Eclipse Application which opens a new Eclipse IDE which provides the plugins functionality) with an plugin B I am writing.
My plugin does run when I run it as a Java Application. Let's assume it just prints Hello World in the console. What I want is that I can call the function which does that from plugin A.
What I did:
I added my plugin B to plugin As Required Plugin-Ins.
I create an instance of the class which implements the Hello World-print and call the function inside a method of plugin A (I also tried to make the method static and call it without creating an instance which resulted in exactly the same errors).
I created an Extension Point in plugin B and added it as an Extension in plugin A. I just set the ID and name in the Extension Point.
What happens:
When the instance of the class in plugin B should be created, the program crashes with this error:
java.lang.NoClassDefFoundError: de/name_of/plugin_b/package/ClassName
[...]
Caused by: java.lang.ClassNotFoundException: de.name_of.plugin_b.package.ClassName cannot be found by de.name_of.plugin_a.package_1.0.0.qualifier
I guess I'm missing something imporant - can someone help me out on what it is?
Edit 2:
I've just read that I have to add "." to the classpath. Seems like this solved the issue! Thanks for making me dig deeper into the manifest, greg!
I do get a different error now tho, which also seems to be connected to me making mistakes when creating the plugin as I do not get this error when I run plugin B as a Java Application.
java.lang.NoSuchMethodError: org.apache.lucene.store.FSDirectory.open(Ljava/nio/file/Path;)Lorg/apache/lucene/store/FSDirectory;
The problem is, tho, that this method does exists (see lucene API here).
As seen in the manifest, I added the lucene-jars to the dependencies of plugin B.
You need to include every package that other plugins use in the Export-Package section of your plugin. In the MANIFEST.MF editor this is on the 'Runtime' tab in the 'Exported Packages' section.
You don't need an extension point to make this work.

Media is not defined - How do I enable Media in a PhoneGap app in Eclipse

I'm developing an application using PhoneGap in Eclipse and whenever I use the Media object I get an exception on this line:
var test = new Media("/android_asset/www/sound/music/Weird.mp3", null, null, null);
12-31 13:52:56.775: E/Web Console(3688): Uncaught ReferenceError:
Media is not defined:25
This exception is, supposedly, due to the fact that I haven't implemented the Media plugin. I just upgraded from 2.9 to 3.3 so there were some changes with the new plugin-system that I haven't used before.
I tried to follow the instructions in the PhoneGap Media documentation but it kept refering to the use of their Command Line Interface. I'm working in Eclipse and I have created the entire project in eclipse, built the Cordova-3.3.0.jar file myself and then added it to the project. Everything works fine up until the use of the Media object.
Anyone have any idea how to add support for Media to a PhoneGap 3.3.0 project? Can I use the CLI on a project created in Eclipse?
I tried to just add support for it by adding the following to my res/xml/config.xml file:
<feature name="Media">
<param name="android-package" value="org.apache.cordova.AudioHandler" />
</feature>
and then adding the proper permissions in my AndroidManifest file:
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
but that didn't work very well either. Any help would be greatly appreciated!
Right. The problem was that I created my Eclipse project using only the Cordova-3.3.0.jar file I had manually built from the source. I should've just created the project using the Command Line Interface as the manual clearly states, added the Media (also through the CLI) and then imported the entire project into Eclipse using File => New => Other => Android from Existing Source.
I got it working now doing it as I described above, hopefully this might help someone some day :P

ClassNotFoundException: previously working Android Project

I had a working android project but needed to start from scratch. I copied all my source files and layout files over. There are no compilation errors but when I try to run, I get the following error.
11-27 17:21:56.793: E/AndroidRuntime(1450): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{projects.mobile.mapappproject/projects.mobile.mapappproject.MainActivity}: java.lang.ClassNotFoundException: Didn't find class "projects.mobile.mapappproject.MainActivity" on path: /data/app/projects.mobile.mapappproject-1.apk
I am running eclipse juno and trying to run on Android 4.2. Thanks !
Rather than doing copy paste try following
1.Create an android application project
2.Delete the files which was created Eg.MainActivity and layout.
2.Right click on project name and click import ,then from File system.Go to your project directory to import the source from there
3.select that, then finish.
4.Clean and build then run
Try these
Add the Activity to AndroidManifest.xml
Is there a difference in your folder names ? For example projects.mobile.mapappproject-1 or projects.mobile.mapappproject !
I copied all my source files and layout files over.
It looks like you forgot to copy over the entries that existed in AndroidManifest.xml, however. Each Activity has an entry there and that entry is required for the framework to find and launch the UI.
I had the same problem, but I found out that a library reference path wasn't right. After I fixed that everything worked fine.
You can check this at Right-click on your project => Properties => Android -> (Library)
Just for the record in case I can help someone :
I had a project that somehow didnt work after importing it from git. I solved this by giving the name of the activity explicitly.
example:
before:
<activity android:name=".Main" [...] /> (relative)
after: <activity android:name="com.example.package.Main" [...] /> (absolute)
This may also occur if you change the manifest package and keep your relative reference (which I think is default).
In my case, following 2 steps fixed the problem
a. Setting compileSdkVersion, buildToolsVersion, targetSdkVersion to the same SDK version in build.gradle.
b. I was missing a dot in application class name in AndroidManifest.xml (Ex. android:name=".ui.ApplicationLoader")

Categories

Resources