make tianium module replace R.layout. or R.id in java class - titanium-mobile

what should I use to replace the R.layout.flash_activity in titanium when building titanium module with ant.
the issue I occured:
error:
jason#jason-Inspiron-3542:/workspace/wechat_login/android$ ant
Buildfile: /workspace/wechat_login/android/build.xml
python.set.exec:
python.check:
[echo] Testing for Python
[exec] Python 2.7.6
init:
process.annotations:
[javac] Compiling 1 source file to /workspace/wechat_login/android/build/classes
[javac] warning: [options] bootstrap class path not set in conjunction with -source 1.6
[javac] warning: The following options were not recognized by any processor: '[kroll.jsonFile, kroll.jsonPackage, kroll.checkTiContext]'
[javac] /workspace/wechat_login/android/src/com/happystock/wxapi/WXEntryActivity.java:18: error: package R does not exist
[javac] setContentView(R.layout.entry);
[javac] ^
[javac] 1 error
[javac] 1 warning
BUILD FAILED
/home/jason/.titanium/mobilesdk/linux/3.5.0.GA/module/android/build.xml:163: Compile failed; see the compiler error output for details.
code:
public class WXEntryActivity extends Activity implements IWXAPIEventHandler{
private IWXAPI api;
private static final String APP_ID = "wx44e8a5248161f***";
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.entry);
api = WXAPIFactory.createWXAPI(this, APP_ID, false);
api.handleIntent(getIntent(), this);
}
Thanks!

Use
int layoutEntry = TiRHelper.getApplicationResource("layout.entry");
setContentView(layoutEntry);
The other thing to make sure is that your resource is actually in platform/android/res/layout/entry.xml or it may not be packaged properly.

I have found a solution on this page that worked for me. You can read more about it there. But if you feel like cutting corners, the code is:
//declaration
View raingBarWrapper;
int resId_raingBarHolder = -1, resId_ratingBar = -1;
//fetching app package name and resources
String packageName = proxy.getActivity().getPackageName();
Resources resources = proxy.getActivity().getResources();
//fetching resource id
resId_raingBarHolder = resources.getIdentifier("raingbar_layout", "layout", packageName);
resId_ratingBar = resources.getIdentifier("ratingbar_default","id", packageName);
LayoutInflater inflater = LayoutInflater.from(getActivity());
//inflating "raingbar_layout" xml file
raingBarWrapper = inflater.inflate(resId_raingBarHolder, null);
//getting reference to RatingBar component in layout
ratingBar = (RatingBar) raingBarWrapper.findViewById(resId_ratingBar);
setNativeView(raingBarWrapper);
//adding properties to RatingBar component
ratingBar.setNumStars(stars);
ratingBar.setStepSize(stepSize);
ratingBar.setRating(rating);

Related

android_intent Error First Install Flutter Plugin

This is the first time I installed the Android_intent plugin in my application,During the experiment I installed plugins in a simple application and the plugin went well, but when I did the same thing in the application I actually had a plugin that no longer worked. but when I installed it an error like this appeared:
/home/denis/AndroidStudioProjects/spmi_conference/build/android_intent/generated/source/buildConfig/debug/io/flutter/plugins/androidintent/AndroidIntentPlugin.java:23: error: duplicate class: io.flutter.plugins.androidintent.AndroidIntentPlugin
public class AndroidIntentPlugin implements MethodCallHandler {
^
/home/denis/Documents/DENISDATA/Jobs/2018/test/flutter/development/flutter/.pub-cache/hosted/pub.dartlang.org/android_intent-0.3.0+2/android/src/main/java/io/flutter/plugins/androidintent/AndroidIntentPlugin.java:13: error: package io.flutter.plugin.common does not exist
import io.flutter.plugin.common.MethodCall;
^
/home/denis/Documents/DENISDATA/Jobs/2018/test/flutter/development/flutter/.pub-cache/hosted/pub.dartlang.org/android_intent-0.3.0+2/android/src/main/java/io/flutter/plugins/androidintent/AndroidIntentPlugin.java:14: error: package io.flutter.plugin.common does not exist
import io.flutter.plugin.common.MethodChannel;
^
/home/denis/Documents/DENISDATA/Jobs/2018/test/flutter/development/flutter/.pub-cache/hosted/pub.dartlang.org/android_intent-0.3.0+2/android/src/main/java/io/flutter/plugins/androidintent/AndroidIntentPlugin.java:15: error: package io.flutter.plugin.common.MethodChannel does not exist
import io.flutter.plugin.common.MethodChannel.MethodCallHandler;
^
/home/denis/Documents/DENISDATA/Jobs/2018/test/flutter/development/flutter/.pub-cache/hosted/pub.dartlang.org/android_intent-0.3.0+2/android/src/main/java/io/flutter/plugins/androidintent/AndroidIntentPlugin.java:16: error: package io.flutter.plugin.common.MethodChannel does not exist
import io.flutter.plugin.common.MethodChannel.Result;
^
/home/denis/Documents/DENISDATA/Jobs/2018/test/flutter/development/flutter/.pub-cache/hosted/pub.dartlang.org/android_intent-0.3.0+2/android/src/main/java/io/flutter/plugins/androidintent/AndroidIntentPlugin.java:17: error: package io.flutter.plugin.common.PluginRegistry does not exist
import io.flutter.plugin.common.PluginRegistry.Registrar;
^
/home/denis/Documents/DENISDATA/Jobs/2018/test/flutter/development/flutter/.pub-cache/hosted/pub.dartlang.org/android_intent-0.3.0+2/android/src/main/java/io/flutter/plugins/androidintent/AndroidIntentPlugin.java:23: error: cannot find symbol
public class AndroidIntentPlugin implements MethodCallHandler {
^
symbol: class MethodCallHandler
/home/denis/Documents/DENISDATA/Jobs/2018/test/flutter/development/flutter/.pub-cache/hosted/pub.dartlang.org/android_intent-0.3.0+2/android/src/main/java/io/flutter/plugins/androidintent/AndroidIntentPlugin.java:25: error: cannot find symbol
private final Registrar mRegistrar;
^
symbol: class Registrar
location: class AndroidIntentPlugin
/home/denis/Documents/DENISDATA/Jobs/2018/test/flutter/development/flutter/.pub-cache/hosted/pub.dartlang.org/android_intent-0.3.0+2/android/src/main/java/io/flutter/plugins/androidintent/AndroidIntentPlugin.java:28: error: cannot find symbol
public static void registerWith(Registrar registrar) {
^
symbol: class Registrar
location: class AndroidIntentPlugin
/home/denis/Documents/DENISDATA/Jobs/2018/test/flutter/development/flutter/.pub-cache/hosted/pub.dartlang.org/android_intent-0.3.0+2/android/src/main/java/io/flutter/plugins/androidintent/AndroidIntentPlugin.java:34: error: cannot find symbol
private AndroidIntentPlugin(Registrar registrar) {
^
symbol: class Registrar
location: class AndroidIntentPlugin
/home/denis/Documents/DENISDATA/Jobs/2018/test/flutter/development/flutter/.pub-cache/hosted/pub.dartlang.org/android_intent-0.3.0+2/android/src/main/java/io/flutter/plugins/androidintent/AndroidIntentPlugin.java:117: error: cannot find symbol
public void onMethodCall(MethodCall call, Result result) {
^
symbol: class MethodCall
location: class AndroidIntentPlugin
/home/denis/Documents/DENISDATA/Jobs/2018/test/flutter/development/flutter/.pub-cache/hosted/pub.dartlang.org/android_intent-0.3.0+2/android/src/main/java/io/flutter/plugins/androidintent/AndroidIntentPlugin.java:117: error: cannot find symbol
public void onMethodCall(MethodCall call, Result result) {
^
symbol: class Result
location: class AndroidIntentPlugin
/home/denis/AndroidStudioProjects/spmi_conference/build/android_intent/generated/source/buildConfig/debug/io/flutter/plugins/androidintent/AndroidIntentPlugin.java:13: error: package io.flutter.plugin.common does not exist
import io.flutter.plugin.common.MethodCall;
^
/home/denis/AndroidStudioProjects/spmi_conference/build/android_intent/generated/source/buildConfig/debug/io/flutter/plugins/androidintent/AndroidIntentPlugin.java:14: error: package io.flutter.plugin.common does not exist
import io.flutter.plugin.common.MethodChannel;
^
/home/denis/AndroidStudioProjects/spmi_conference/build/android_intent/generated/source/buildConfig/debug/io/flutter/plugins/androidintent/AndroidIntentPlugin.java:15: error: package io.flutter.plugin.common.MethodChannel does not exist
import io.flutter.plugin.common.MethodChannel.MethodCallHandler;
^
/home/denis/AndroidStudioProjects/spmi_conference/build/android_intent/generated/source/buildConfig/debug/io/flutter/plugins/androidintent/AndroidIntentPlugin.java:16: error: package io.flutter.plugin.common.MethodChannel does not exist
import io.flutter.plugin.common.MethodChannel.Result;
^
/home/denis/AndroidStudioProjects/spmi_conference/build/android_intent/generated/source/buildConfig/debug/io/flutter/plugins/androidintent/AndroidIntentPlugin.java:17: error: package io.flutter.plugin.common.PluginRegistry does not exist
import io.flutter.plugin.common.PluginRegistry.Registrar;
^
/home/denis/Documents/DENISDATA/Jobs/2018/test/flutter/development/flutter/.pub-cache/hosted/pub.dartlang.org/android_intent-0.3.0+2/android/src/main/java/io/flutter/plugins/androidintent/AndroidIntentPlugin.java:29: error: cannot find symbol
final MethodChannel channel =
^
symbol: class MethodChannel
location: class AndroidIntentPlugin
/home/denis/Documents/DENISDATA/Jobs/2018/test/flutter/development/flutter/.pub-cache/hosted/pub.dartlang.org/android_intent-0.3.0+2/android/src/main/java/io/flutter/plugins/androidintent/AndroidIntentPlugin.java:30: error: cannot find symbol
new MethodChannel(registrar.messenger(), "plugins.flutter.io/android_intent");
^
symbol: class MethodChannel
location: class AndroidIntentPlugin
/home/denis/Documents/DENISDATA/Jobs/2018/test/flutter/development/flutter/.pub-cache/hosted/pub.dartlang.org/android_intent-0.3.0+2/android/src/main/java/io/flutter/plugins/androidintent/AndroidIntentPlugin.java:116: error: method does not override or implement a method from a supertype
#Override
^
20 errors
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':android_intent:compileDebugJavaWithJavac'.
> Compilation failed; see the compiler error output for details.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 2s
Finished with error: Gradle task assembleDebug failed with exit code 1
I have tried this for several days.
am I wrong with my code?
can someone help me? thank you
best regards.
Add this code into your project's android build Gradle file.
subprojects {
project.evaluationDependsOn(':app')
project.configurations.all {
resolutionStrategy.eachDependency { details ->
if (details.requested.group == 'androidx.core'
&& !details.requested.name.contains('androidx')) {
details.useVersion "1.0.1"
}
}
}
}
Dont forget to clean your project before trying again.
I just had the same problem with another plugin, and found little useful information. The steps that ultimately worked for me were to:
Upgrade the version of gradle:
In android/gradle/wrapper/gradle-wrapper.properties I switched to using 5.4.1
In android/build.gradle I switched to classpath 'com.android.tools.build:gradle:3.5.1'
Ensuring that AndroidX support libraries are used:
In android/app/build.gradle this was a matter of switching all android.support prefixes to androidx.support (and com.android.support to com.androidx.support, respectively).
Based on my experimentation, I believe it is #2 that is the root cause of the problem - indeed, step #1 may be entirely unnecessary, but seemed like a reasonable place to start while I was trying to figure out what the problem was.
As you did not provide information about your gradle properties, I can only assume that you are facing a similar issue based on the similarity in build issues encountered.

Unity cannot build GRPC Project for UWP with IL2CPP Backend

Here, or here for a complete version, you can find a sample GRPC "Hello World" project for Unity. Only the first version, that is built for Unity and wrapped in a DLL is working perfectly fine in Unity IDE and on Standalone build. The Raw Grpc.Core files are referencing everything correctly in IDE but they have Marshaling problem.
Unfortunately, it cannot get build for UWP with IL2CPP backend. Unity builds the project and creates a .sln project. But Visual Studio always gives LNK2001 for GRPC properties on the final compilation.
Here are first error codes:
LNK2001 unresolved external _grpccsharp_init#0
LNK2001 unresolved external _grpccsharp_shutdonw#0
LNK2001 unresolved external _grpccsharp_version_string#0
...
Ok, thanks to #Sunius, I digged into it a little bit more. There are some points, I am going to add to the question:
There are two methods regarding referencing extern methods in GRPC C# package. They are named static and shared libs.
internal class DllImportsFromStaticLib
{
private const string ImportName = "__Internal";
[DllImport(ImportName)]
public static extern void grpcsharp_init();
[DllImport(ImportName)]
public static extern void grpcsharp_shutdown();
...
}
and
internal class DllImportsFromSharedLib
{
private const string ImportName = "grpc_csharp_ext";
[DllImport(ImportName)]
public static extern void grpcsharp_init();
[DllImport(ImportName)]
public static extern void grpcsharp_shutdown();
...
}
I tried to test it with the shared one, I got another linking error file which is a little bit different.
LNK2001 unresolved external _dlopen#8
LNK2001 unresolved external _dlsym#8
...
In two separate methods, extern methods are getting connected to the internal interface:
public NativeMethods(DllImportsFromStaticLib unusedInstance)
{
this.grpccsharp_init = DllImportsFromStaticLib.grpccsharp_init;
this.grpccsharp_shutdown = DllImportsFromStaticLib.grpccsharp_shutdonw;
...
}
and
public NativeMethods(DllImportsFromSharedLib unusedInstance)
{
this.grpccsharp_init = DllImportsFromSharedLib.grpccsharp_init;
this.grpccsharp_shutdown = DllImportsFromSharedLib.grpccsharp_shutdonw;
...
}
And which method will get called is defined here:
private static NativMethods LoadNativeMethodsUnity()
{
switch(PlatformApis.GetUnityRuntimePlatform())
{
case "IPhonePlayer":
return new NativeMethods(new NativeMethods.DllImportsFromStaticLib());
default:
return new NativeMethods(new NativeMethods.DllImportsFromSharedLib());
}
}
Some updates:
Thanks to #jsmouret, there is Stub.c file in his Grpc Github with fake methods, so Linker does not complain about Grpc_init methods anymore.
Next Error: dlopen, dlsym, dlerror:
First, I tried to use the same, Stub technique, but it did not help in this case, or maybe I did it wrong.
Thanks to #Sunius, I commented out all of "__Internal" dll import codes. So I am not getting any dlopen, dlsym, and dlerror errors.
Next Error: It happens from inside application, not the visual studio debugger. It tells me: "exception: to marshal a managed method, please add an attribute named 'MonoPInvokeCallback' to the method definition."
exception: error loading the embedded resource "Grpc.Core.roots.pem"
and
exception: To marshal a managed method, please add an attribute named 'MonoPInvokeCallback' to the method definition.
After I googled it, I know my options, but the question it, for which method should I do that?!
Thanks to my colleague Alice, #Sunius and #jsmouret, at the end, grpc works on UWP on Unity Platform through this steps:
Download Grpc.Core folder from Google Grpc Github.
Download Grpc Unity plugin from their official site.
Copy the runtime folder to your Grpc.Core folder. Please remove Grpc.Core.dll that you get from Grpc Unity Plugin, since we are using their source code.
Grpc should be in a folder called, Plugins in Unity, otherwise it will not be recognized.
Include this file in your runtime folder.
Include the Stub also from the Unity Plugin Inspector for WSA.
Find runtime .dll for Windows and include them in WSA from Unity Plugin Inspector.
By now, you should be getting _dlopen error.
Search through your Unity Solution with an IDE for "__Internal". There are not so many places, but comment them out. Also some methods that are depended on "__Internal"s, like dlopen and dlsym.
By now, you are not getting anymore build error but you need to make Grpc work.
Search for something like "DefaultSslRootsOverride" and comment out like below:
internal static class DefaultSslRootsOverride
{
const string RootsPemResourceName = "Grpc.Core.roots.pem";
static object staticLock = new object();
/// <summary>
/// Overrides C core's default roots with roots.pem loaded as embedded resource.
/// </summary>
public static void Override(NativeMethods native)
{
lock (staticLock)
{
//var stream = typeof(DefaultSslRootsOverride).GetTypeInfo().Assembly.GetManifestResourceStream(RootsPemResourceName);
//if (stream == null)
//{
// throw new IOException(string.Format("Error loading the embedded resource \"{0}\"", RootsPemResourceName));
//}
//using (var streamReader = new StreamReader(stream))
//{
// var pemRootCerts = streamReader.ReadToEnd();
// native.grpcsharp_override_default_ssl_roots(pemRootCerts);
//}
}
}
}
Search for something like "static void HandWrite" and add an attribute like something in below:
[MonoPInvokeCallback(typeof(GprLogDelegate))]
private static void HandleWrite(IntPtr fileStringPtr, int line, ulong threadId, IntPtr severityStringPtr, IntPtr msgPtr)
{
try
{
var logger = GrpcEnvironment.Logger;
string severityString = Marshal.PtrToStringAnsi(severityStringPtr);
string message = string.Format("{0} {1}:{2}: {3}",
threadId,
Marshal.PtrToStringAnsi(fileStringPtr),
line,
Marshal.PtrToStringAnsi(msgPtr));
switch (severityString)
{
case "D":
logger.Debug(message);
break;
case "I":
logger.Info(message);
break;
case "E":
logger.Error(message);
break;
default:
// severity not recognized, default to error.
logger.Error(message);
break;
}
}
catch (Exception e)
{
Console.WriteLine("Caught exception in native callback " + e);
}
}
I guess, you are done. In case, it did not work for your UWP, let me know, maybe I can help. :)
It looks like your plugin uses "__Internal" P/Invoke to call those native functions:
https://github.com/grpc/grpc/blob/befc7220cadb963755de86763a04ab6f9dc14200/src/csharp/Grpc.Core/Internal/NativeMethods.Generated.cs#L542
However, the linker cannot locate those functions and thus fails. You should change that code to either specify the DLL file name where the functions are implemented, or drop the source files with definitions for those functions into your Unity project. Or, if that code path isn't actually invoked (since you said it works on the standalone player), #ifdef it out from UWP build.
You can find more information about "__Internal" P/Invoke here:
https://docs.unity3d.com/Manual/windowsstore-plugins-il2cpp.html

TypeLoadException: Could not load type from assembly in Xamarin

I have Xamarin Forms PCL application and I am trying to inherit from HttpContent in attempt to follow this reference. I would like to implement progress bar for image upload. Here is my implementation which contains minimum code to implement HttpContent:
public class ProgressableStreamContent : HttpContent
{
public ProgressableStreamContent()
{ }
protected override Task SerializeToStreamAsync(Stream stream, TransportContext context)
{
return Task.Run(async () =>
{
});
}
protected override bool TryComputeLength(out long length)
{
length = 0;
return true;
}
}
and I have procedure that is using this ProgressableStreamContent:
public async void UseProgressableStreamContent()
{
var progressableContent = new ProgressableStreamContent();
}
Problem is that this code produces exception:
UNHANDLED EXCEPTION: System.TypeLoadException: Could not load type 'MyApp.Classes.ProgressableStreamContent' from assembly 'MyApp, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'.
When I comment out line "var progressableContent = new ProgressableStreamContent();" - everything works good.
When I comment out inheritance ": HttpContent" (and override keywords) - everything works good.
Should I install some package? What else could be a problem?
I resolved issue by changing profile from 259 to 7. Changing profile includes deleting all NuGet packages and installing them again after profile change.

TypeScript dynamic loading of AMD module ends in "Could not find symbol '...'

No, this topic won't answer my question and NO, the solution is not simply importing Command in the nav.ts file. nav.ts is one of many viewModel-files and they will be loaded dynamically on demand. The only problem is to set the parameter's type in the constructor of the class. (Type has to be "Command")
In the following class, which will be loaded by require.js, the method viewModel() requires a new class dynamically. In this case NavViewModel .
command.ts
export class Command {
...
public viewModel(name: string, callback: Function) {
require(["noext!boot/getViewModel/" + name], function (viewModel) {
callback(viewModel);
});
}
}
This is the class which will be fetched by viewModel():
nav.ts
export class NavViewModel extends kendo.Router {
constructor(command: Command) {
super();
this.route('/:name', function (name) {
command.view(name, $('div.content'));
});
this.start();
}
}
EDIT:
Here is the entry-point (requested in comment 2)
main.ts (EntryPoint)
import lib = require("command");
var cmd = new lib.Command();
cmd.viewModel('nav', function (o) {
cmd.view('nav', $('div.header'), function () {
kendo.bind($('.header .nav'), new o.NavViewModel(cmd));
});
});
/EDIT
The Problem:
Visual Studio will throw the error TS2095: Could not find symbol 'Command', because the "Command" class ist not defined in this Module.
The program works fine if the "Command"-Type will be removed from the NavViewModel constructor. Is there any solution to reference the Command class in the NavViewModel?
This won't work:
/// <reference path="../../Scripts/command.ts" />
When using RequireJS, the import statement should be the full path from the root of the application.
I also use a slightly different export syntax
command.ts
class command {
...
}
export = command;
main.ts
// I'm assuming the Scripts folder is at the root of the application
import Command = require('Scripts/command');
var cmd = new Command();
Note
I'm using Typescript 0.9.1.1. I can't upgrade my machine to 0.9.5 as a large internal application is affected by some breaking changes between versions

How to discovering types exported by OSGi bundle without installing/activating?

Basically i want to discover if a jar implements any number of interfaces wihtout activating or starting the bundle. Is it possible to read the meta data from the meta-inf from an API just like the container does but without activating a bundle ?
I want to use OSGi to support plugins of which numerous interfaces will be published and i would like to know which interfaces are implemented by a bundle when the user uploads without activating the bundle etc.
I do not think it is possible to discover what services a bundle is going to provide, because this can happen from inside the Java code, without any meta-data about it. Of course, if you use Declarative Services, there is a meta-data file. Also, the bundle needs to import (or provide) the service interface, which may give you a hint (but not more).
You can inspect what Java packages a bundles imports and exports without activating it.
If you are willing to install (not resolve, not activate) it, you can query it. The Felix or Equinox shells can list those packages after all.
Here is the relevant source from Felix' shell. It uses the PackageAdmin service:
public void execute(String s, PrintStream out, PrintStream err)
{
// Get package admin service.
ServiceReference ref = m_context.getServiceReference(
org.osgi.service.packageadmin.PackageAdmin.class.getName());
PackageAdmin pa = (ref == null) ? null :
(PackageAdmin) m_context.getService(ref);
// ...
Bundle bundle = m_context.getBundle( bundleId );
ExportedPackage[] exports = pa.getExportedPackages(bundle);
// ...
}
you may try something like below. Find the ".class" files in the exported packages using bundle.findResource(...) method.
BundleContext context = bundle.getBundleContext();
ServiceReference ref = context.getServiceReference(PackageAdmin.class.getName());
PackageAdmin packageAdmin = (PackageAdmin)context.getService(ref);
List<Class> agentClasses = new ArrayList<Class>();
ExportedPackage[] exportedPackages = packageAdmin.getExportedPackages(bundle);
for(ExportedPackage ePackage : exportedPackages){
String packageName = ePackage.getName();
String packagePath = "/"+packageName.replace('.', '/');
//find all the class files in current exported package
Enumeration clazzes = bundle.findEntries(packagePath, "*.class", false);
while(clazzes.hasMoreElements()){
URL url = (URL)clazzes.nextElement();
String path = url.getPath();
int index = path.lastIndexOf("/");
int endIndex = path.length()-6;//Strip ".class" substring
String className = path.substring(index+1, endIndex);
String fullClassName=packageName+"."+className;
try {
Class clazz = bundle.loadClass(fullClassName);
//check whether the class is annotated with Agent tag.
if(clazz.isAnnotationPresent(Agent.class))
agentClasses.add(clazz);
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
}
}

Resources