gles2 动态壁纸转换为 c# (xamarin) 符合错误“...mono.android.TypeManager 无法应用于

Posted

技术标签:

【中文标题】gles2 动态壁纸转换为 c# (xamarin) 符合错误“...mono.android.TypeManager 无法应用于【英文标题】:gles2 live wallpaper converted to c# (xamarin) complies with error "...mono.android.TypeManager cannot be applied to 【发布时间】:2013-02-01 14:40:53 【问题描述】:

我正在尝试在 c# 中使用 xamarin 编写 android 动态壁纸。 为此,我将此处找到的 GLWallPaperService 代码转换为 c#:http://www.learnopengles.com/how-to-use-opengl-es-2-in-an-android-live-wallpaper/ (这里直接跳转到java实现:https://github.com/learnopengles/Learn-OpenGLES-Tutorials/tree/master/android/AndroidOpenGLESLessons/src/com/learnopengles/android/livewallpaper) 编译时出现错误:

Mono.android.TypeManager 中的 Activate(java.lang.String,java.lang.String,java.lang.Object,java.lang.Object[]) 无法应用于 (java.lang.String,java.lang.String ,com.[redacted].OpenGLES2WallpaperService.OpenGLES2WallpaperService_OpenGLES2Engine,java.lang.Object[]) mono.android.TypeManager.Activate ("com.[redacted].OpenGLES2WallpaperService/OpenGLES2Engine, GameUtilClassLibrary, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null", "com.[redacted].WallpaperServiceUtil.OpenGLES2WallpaperService, GameUtilClassLibrary, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null", this, new java.lang.Object[] OpenGLES2WallpaperService.this ); D:\[编辑]\obj\Debug\android\src\com\[编辑]\wallpaperserviceutil\OpenGLES2WallpaperService.java

这是我的 c# 实现...抱歉,篇幅较长:

public abstract class GLWallpaperService : WallpaperService

    public class GLEngine : Engine
    
        private readonly GLWallpaperService outerInstance;

        public GLEngine(GLWallpaperService outerInstance) : base(outerInstance)
        
            this.outerInstance = outerInstance;
        

        internal class WallpaperGLSurfaceView : GLSurfaceView
        
            private readonly GLWallpaperService.GLEngine outerInstance;
            ISurfaceHolder _surfaceHolder;

            internal WallpaperGLSurfaceView(GLWallpaperService.GLEngine outerInstance, Context context, ISurfaceHolder surfaceHolder)
                : base(context)
            
                this.outerInstance = outerInstance;
                _surfaceHolder = surfaceHolder;
            

            public override ISurfaceHolder Holder
            
                get
                
                    return _surfaceHolder;
                
            

            public virtual void OnDestroy()
            
                base.OnDetachedFromWindow();
            
        

        private WallpaperGLSurfaceView glSurfaceView;
        private bool rendererHasBeenSet;

        public override void OnCreate(ISurfaceHolder surfaceHolder)
        
            base.OnCreate(surfaceHolder);

            glSurfaceView = new WallpaperGLSurfaceView(this, outerInstance, surfaceHolder);
        

        public override void OnVisibilityChanged(bool visible)
        
            base.OnVisibilityChanged(visible);

            if (rendererHasBeenSet)
            
                if (visible)
                
                    glSurfaceView.OnResume();
                
                else
                
                    if (!IsPreview)
                    
                        glSurfaceView.OnPause();
                    
                
            
        

        public override void OnDestroy()
        
            base.OnDestroy();
            glSurfaceView.OnDestroy();
        

        protected internal virtual Android.Opengl.GLSurfaceView.IRenderer NewRenderer//was just Renderer
        
            set
            
                glSurfaceView.SetRenderer(value);
                rendererHasBeenSet = true;
            
        

        protected internal virtual int EGLContextClientVersion
        
            set
            
                glSurfaceView.SetEGLContextClientVersion(value);
            
        
    


public abstract class OpenGLES2WallpaperService : GLWallpaperService

    public override Engine OnCreateEngine()
    
        return new OpenGLES2Engine(this);
    

    internal class OpenGLES2Engine : GLWallpaperService.GLEngine
    
        private readonly OpenGLES2WallpaperService outerInstance;

        public OpenGLES2Engine(OpenGLES2WallpaperService outerInstance)
            : base(outerInstance)
        
            this.outerInstance = outerInstance;
        

        public override void OnCreate(ISurfaceHolder surfaceHolder)
        
            base.OnCreate(surfaceHolder);

            // Check if the system supports OpenGL ES 2.0.
            //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
            //ORIGINAL LINE: final android.app.ActivityManager activityManager = (android.app.ActivityManager) getSystemService(android.content.Context.ACTIVITY_SERVICE);
            ActivityManager activityManager = (ActivityManager)outerInstance.GetSystemService(Context.ActivityService);
            //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
            //ORIGINAL LINE: final android.content.pm.ConfigurationInfo configurationInfo = activityManager.getDeviceConfigurationInfo();
            ConfigurationInfo configurationInfo = activityManager.DeviceConfigurationInfo;
            //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
            //ORIGINAL LINE: final boolean supportsEs2 = configurationInfo.reqGlEsVersion >= 0x20000;
            bool supportsEs2 = configurationInfo.ReqGlEsVersion >= 0x20000;

            if (supportsEs2)
            
                // Request an OpenGL ES 2.0 compatible context.
                EGLContextClientVersion = 2;

                // Set the renderer to our user-defined renderer.
                NewRenderer = outerInstance.NewRenderer;//was just Renderer
            
            else
            
                // This is where you could create an OpenGL ES 1.x compatible
                // renderer if you wanted to support both ES 1 and ES 2.
                return;
            
        
    

    internal abstract Android.Opengl.GLSurfaceView.IRenderer NewRenderer  get; 


public class LessonThreeWallpaperService : OpenGLES2WallpaperService

    internal override Android.Opengl.GLSurfaceView.IRenderer NewRenderer
    
        get
        
            return new LessonThreeRenderer(); // is a GLSurfaceView.IRenderer
        
    

我的目标是 sdk 版本 8 并使用 Visual Studio 2012。 任何帮助表示赞赏。

【问题讨论】:

【参考方案1】:

这是我们的 Android Callable Wrapper 生成器代码中的一个错误:我们不正确地支持来自 C# 的“中间”非静态内部类。具体来说,GLWallpaperService.Engine 是正确生成的,但 OpenGLES2WallpaperService.OpenGLES2Engine 不是。

请在bugzilla.xamarin.com 提交错误。

【讨论】:

以上是关于gles2 动态壁纸转换为 c# (xamarin) 符合错误“...mono.android.TypeManager 无法应用于的主要内容,如果未能解决你的问题,请参考以下文章

Xamarin 表单将 Json 数组转换为 C# 并返回 JSON 数组

如何使用 c# 在 Xamarin.Ios 中将 UIColor 转换为字符串和字符串转换为 UIColor

关于使用 C#(Xamarin 开发环境)从浮点矩阵转换为 Java.Lang.Object 的问题

将android java转换为xamarin c#

Xamarin C# Android - 将 .3gpp 音频转换为字节并发送到 parseObject

Xamarin.iOS,将 Dictionary 转换为 NSDictionary