I updated Android studio to 3.2.1 and run 'flutter build apk' in terminal of Mac, it shows below error. I was able to build apk successfully before updated Android studio.
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:transformClassesAndResourcesWithProguardForRelease'.
> Job failed, see logs for details
here with my proguard-rules.pro
#Flutter Wrapper
-keep class io.flutter.app.** { *; }
-keep class io.flutter.plugin.** { *; }
-keep class io.flutter.util.** { *; }
-keep class io.flutter.view.** { *; }
-keep class io.flutter.** { *; }
-keep class io.flutter.plugins.** { *; }
-keep class com.google.firebase.** { *; }
This fixed my issue,
#Flutter Wrapper
-keep class io.flutter.app.** { *; }
-keep class io.flutter.plugin.** { *; }
-keep class io.flutter.util.** { *; }
-keep class io.flutter.view.** { *; }
-keep class io.flutter.** { *; }
-keep class io.flutter.plugins.** { *; }
-dontwarn android.**
Check explanation here:
https://github.com/flutter/flutter/issues/40218#issuecomment-531047713
Goto android/app/build.gradle and try minifyEnabled false it should work
Related
I create a module in drupal 8 .
I want using a class in external class file .
File name : drupal.php
Class name : class newman{...}
In drupal.php :
<?php
namespace Drupal\mymodulename\lib;
class newman{
public function new(){
$dp = 'TEST';
return $dp;
}
}
?>
In my contoller :
<?php
namespace Drupal\mymodulename\Controller;
use Drupal\Core\Controller\ControllerBase;
use Drupal\mymodulename\lib\drupal;
class mmController extends ControllerBase {
public function man() {
$this->man=new newman();
$build['test'] = [
'#markup' => $man->new(),
];
}
}
Error: Class 'Drupal\mymodulename\Controller\newman' not found in Drupal...
How can I fix it ?
create your class file as field plugin
moduleName/src/Plugin/Field/FieldFormatter/NewMan.php
file name and class name should be same
<?php
namespace Drupal\moduleName\Plugin\Field\FieldFormatter;
class NewMan {
//class content
}
then use it any where
//include file
use Drupal\moduleName\Plugin\Field\FieldFormatter\NewMan;
// use
$newMan =new NewMan();
Hope this solve your problem
Dont forget to mark as answers if this solve your problem thanks.
Good luck
In the drupal.php file, which should be renamed to Newman.php (Coding standards), Also remove the closing PHP tag here.
<?php
namespace Drupal\mymodulename\lib;
class Newman {
public function new(){
$dp = 'TEST';
return $dp;
}
}
In your controller
<?php
namespace Drupal\mymodulename\Controller;
use Drupal\Core\Controller\ControllerBase;
use Drupal\mymodulename\lib\Newman;
class mmController extends ControllerBase {
public function man() {
$man = new Newman();
$build['test'] = [
'#markup' => $man->new(),
];
}
}
I am new to dryioc so excuse the ignorance:)
I would like to understand what the correct approach would be for the following,
Creating a console app that creates instance of dryioc container. Register a logger in the container (as singleton). Then instantiate a class from a class library (separate project) to be used in the console app and be able to reference the container (main app) from the class library to get an instance of logger. So the class library will utilise any logger registered in console app.
I'd prefer not to pass container as part of constructors in class library.
Thanks for any assistance.
Something like this. Probably true for any other container (or even without container):
namespace Core
{
public interface ILogger
{
void Log(string message);
}
}
namespace Lib
{
using Core;
public class Foo
{
readonly ILogger _logger;
public Foo(ILogger logger)
{
_logger = logger;
}
public void DoSomething()
{
_logger.Log("About to do something ...");
}
}
}
namespace ConsoleApp
{
using System;
using Core;
using Lib;
using DryIoc;
public class ConsoleLogger : ILogger
{
public void Log(string message)
{
Console.WriteLine(message);
}
}
public class Program
{
public static void Main()
{
var c = new Container();
c.Register<ILogger, ConsoleLogger>(Reuse.Singleton);
c.Register<Foo>();
var foo = c.Resolve<Foo>();
foo.DoSomething();
}
}
}
I am using powermock and meet two problems like this:
public LogUtils {
public static enum Type {
****
}
public void log(Type type, Date date) {
***
}
}
public class Service {
public int call() {
LogUtils.log(Type.T1, new Date());
***
return *;
}
}
#RunWith(PowerMockRunner.class)
public class TestService {
#Test
#PrepareForTest(LogUtils.class)
public void test() {
Service service = new Service();
PowerMockito.mockStatic(LogUtils.class);
LogUtils.log(Type.T1, new Date()); // test here, but failed.
service.
}
#Test
#PrepareForTest(LogUtils.class)
public void test2() {
Service service = new Service();
PowerMockito.mockStatic(LogUtils.class);
LogUtils.log(Type.T1, new Date());
int ret = service.call();
Assert.isTrue(1, ret);
}
}
For test1, it would throw Exception:
java.lang.VerifyError: Bad type on operand stack in arraylength
Exception Details:
Location:
LogUtilss$Type.values()[LogUtils$Type; #137: arraylength
Reason:
Invalid type: 'java/lang/Object' (current frame, stack[2])
Current Frame:
bci: #137
flags: { }
locals: { 'java/lang/Object', top, top, top, 'java/lang/Object' }
stack: { 'java/lang/Object', integer, 'java/lang/Object' }
it is caused by defining static enum in class instead of directly creating enum with single file. How to solve this problem as our codes almost define static enum in class?
For test2, if the first problem is solved, the direct call of LogUtils.log could be successfully skipped, but when call service.call(), couldn't skip.
Anyone could kindly help on this? Thanks a lot in advance.
I use powermock 1.6.5 and JDK1.7
Full code example:
public class LogUtils {
public static enum Type {
T(1),
D(2);
private int type;
Type(int type) {
type = type;
}
}
public static void log(Type t, String msg) {
System.out.println("skip this method");
}
}
public class TestAction {
public void test() {
String msg = "logMsg";
LogUtils.log(LogUtils.Type.T, msg);
}
}
import org.junit.Test;
import org.junit.runner.RunWith;
import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
#RunWith(PowerMockRunner.class)
public class UnitTest {
#Test
#PrepareForTest(LogUtils.class)
public void test() {
PowerMockito.mockStatic(LogUtils.class);
TestAction a = new TestAction();
LogUtils.log(LogUtils.Type.T, "test");
a.test();
}
}
Expect: no print for 'skip this method'.
I discovered an odd anomaly with NSubstitute class instantiation. Working with Sitecore 8.1 update 3 Sitecore.Kernell.dll, the following test passes:
[Fact]
public void CanCreateSubstituteDatabase()
{
Database db = Substitute.For<Sitecore.Data.Database>("sub");
db.Should().NotBeNull();
}
This despite the fact that there is only an internal constructor for Sitecore.Data.Database:
internal Database(string name)
{....
I have confirmed that this is not normal behavior for NSubstitute. I created a project "ExternalLibrary" with this code:
namespace ExternalLibrary
{
public class Foo
{
internal Foo(string bar)
{
Bar = bar;
}
public string Bar { get; }
}
}
When I try to use NSubstitute to instantiate this in a separate library,
namespace NSubClassInstantiation
{
using ExternalLibrary;
using FluentAssertions;
using NSubstitute;
using Xunit;
public class FooTest
{
[Fact]
public void CanInstantiate()
{
var foo = Substitute.For<Foo>("baz");
foo.Bar.Should().Be("baz");
}
}
}
the test fails as expected with the following exception,
System.NotSupportedException: Parent does not have a default constructor. The default constructor must be explicitly defined.
Why is this error not thrown with the Sitecore.Data.Database class?
NSubstitute namespace is marked InternalsVisibleTo in Sitecore.Kernel.
What is the DynamicProxyGenAssembly2 assembly?
From Sitecore.Kernel: [assembly: InternalsVisibleTo("DynamicProxyGenAssembly2")]
Toy example code:
public abstract class testBase
{
public testBase()
{
//Some common test setup code, which will initialize ManagerClass
}
}
public class someTests: testBase
{
public someTests()
{
//someTests-specific constructor code.
}
[Theory]
[PropertyData("MyTestData")]
public void test1(Foo foo)
{
//Use foo to do a test
}
public static IEnumerable<object[]> MyTestData
{
get
{
yield return new object[] { ManagerClass.CreateANewFoo(1) };
yield return new object[] { ManagerClass.CreateANewFoo(42) };
}
}
}
In the above example, if I specifically run test1 (I'm using Resharper, but the problem also occurs when I use the xUnit GUI) my test is failing because it seems that neither the testBase nor someTests constructors are being executed. Hence the call to ManagerClass.CreateANewFoo() is throwing a NullReference.
If I run all of the tests in someTests, or any other individual test, the constructor executes as expected and the tests proceed in the expected fashion. The only thing that marks test1 out as different is the fact that it is using the PropertyData attribute.
Any ideas why this is happening/what I'm doing wrong?
We attempted to reproduce this with xUnit.net 1.5 Beta and cannot.