Overriding AndroidManifest with 2 different flavor got ClassNotFoundException errors when running - build.gradle

I am trying to make 2 flavors of my app, the build is successful, but I could not run the app, it just throws out errors,
java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.xxx.xxxx.pro/com.xxx.xxxx.pro.MainDrawerActivity}: java.lang.ClassNotFoundException: Didn't find class "com.xxx.xxxx.pro.MainDrawerActivity" on path: DexPathList[[zip file "/data/app/~~M5SYRD20kL-vRCPFn4v8Hg==/com.xxx.xxxx.pro-QkEX9F-RWJNacQveaOvpqg==/base.apk"],nativeLibraryDirectories=[/data/app/~~M5SYRD20kL-vRCPFn4v8Hg==/com.xxx.xxxx.pro-QkEX9F-RWJNacQveaOvpqg==/lib/x86, /system/lib, /system_ext/lib]]
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3365)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3601)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
...
The build.gradle is something like this:
productFlavors {
free {
applicationId "com.xxx.xxxx"
}
pro {
versionNameSuffix "-pro"
applicationId 'com.xxx.xxxx.pro'
}
}
sourceSets {
pro {
res.srcDirs = ['src/pro/res']
manifest.srcFile 'src/pro/AndroidManifest.xml'
}
}
I have put each AndroidManifest.xml in the main folder and pro folder.
📂src
|--📂main
| \__ AndroidManifest.xml
`--📂pro
\__ AndroidManifest.xml
Currently, the two AndroidManifest files are nearly the same, except package name in the <manifest> node and android:icon, android:label in the <application> node.
I have tried a lot of different things but still have no luck. What is the correct way to make flavor works?

Related

Jaxb Plugin Issue with gradle7 and jdk11

I am trying to run build locally using gradle 7.4 and jdk 11 with below setting in build.gradle.
apply plugin: 'com.github.jacobono.jaxb'
dependencies {
.....
jaxb "com.sun.xml.bind:jaxb-xjc:3.0.2"
jaxb "com.sun.xml.bind:jaxb-impl:3.0.2"
}
jaxb {
xsdDir='src/main/resources/xsd' // Define the folder for location of the schema file
xjc {
generatePackage 'com.demo.bizid.entities' // Set the package name for generated source files
destinationDir='build/jaxb-generated'
}
}
sourceSets.main.java.srcDirs 'build/jaxb-generated'
tasks.withType(JavaCompile) {
dependsOn xjc
}
But getting build issue with below error
Some problems were found with the configuration of task ':xsd-dependency-tree' (type 'JaxbDependencyTree').
- In plugin 'com.github.jacobono.jaxb' type 'org.gradle.jacobo.plugins.task.JaxbDependencyTree' property 'dependencyTreeFactory' is missing an input or output annotation.
Reason: A property without annotation isn't considered during up-to-date checking.

aspnetcore: how to return a view from middleware

I'm working at a middleware for aspnetcore2.0 where I want to execute some razor view.
Actually I need a error handling middleware which would show nice pages from razor views. I know that it's possible to do with UseStatusCodePagesWithReExecute based on status codes. But I need a more general approach - handle an exception in my middleware to delegate (in some cases) it to an error view.
I realized that DeveloperExceptionPageMiddleware does something similar to what I need. But I can't understand how it works even after digging into its sources.
Here is the place where that middleware returns a view - https://github.com/aspnet/Diagnostics/blob/dev/src/Microsoft.AspNetCore.Diagnostics/DeveloperExceptionPage/DeveloperExceptionPageMiddleware.cs#L206
But I can't understand what kind of view it is. It's nor a razor page (as it has no #page directive) neither an mvc view (but i'm not sure).
In the project there're two files for that view: ErrorPage.cshtml and ErrorPage.Designer.cs. How that Designer.cs was created? It looks like a generated file. But thanks to it there's a normal class in the project (ErrorPage) which can be used explicitly. It inherits Microsoft.Extensions.RazorViews.BaseView class from Microsoft.Extensions.RazorViews.Sources package.
So the middleware just execute that view:
var errorPage = new ErrorPage(model);
return errorPage.ExecuteAsync(context);
How can it be achieved in my project?
UPDATE [2018.06]: Please note that the post was written for .NET Core 2.0 times, there're breaking changes for RazorEngine in .NET Core 2.1.
It turned out that it's pretty easy to do.
Aspnet prjoect has an internal tool called RazorPageGenerator (see https://github.com/aspnet/Razor/tree/dev/src/RazorPageGenerator) which can be used to compile views. After compilation with this tool we'll get normal classes which can be used in middlewares.
But before we need to get RazorPageGenerator and slightly customize it.
1.Create a new console project
dotnet new console -o MyRazorGenerator
2.put NuGet.config inside this folder
<configuration>
<config>
<add key="globalPackagesFolder" value="./packages" />
</config>
<packageSources>
<add key="aspnetcore-dev" value="https://dotnet.myget.org/F/aspnetcore-dev/api/v3/index.json " />
</packageSources>
</configuration>
3.Add the following in csprj (as dotnet add package doesn't support installing pre-prelease packages)
<ItemGroup>
<PackageReference Include="RazorPageGenerator" Version="2.1.0-*" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Razor.Extensions" Version="2.1.0-*" />
<PackageReference Include="Microsoft.AspNetCore.Razor.Language" Version="2.1.0-*" />
</ItemGroup>
4.restore dotnet restore to check you got RazorPageGenerator
5.add into Program.cs:
public static int Main(string[] args)
{
if (args == null || args.Length < 1)
{
Console.WriteLine("Invalid argument(s).");
return 1;
}
var rootNamespace = args[0];
var targetProjectDirectory = args.Length > 1 ? args[1] : Directory.GetCurrentDirectory();
var razorEngine = RazorPageGenerator.Program.CreateRazorEngine(rootNamespace, builder => {
FunctionsDirective.Register(builder);
InheritsDirective.Register(builder);
SectionDirective.Register(builder);
});
var results = RazorPageGenerator.Program.MainCore(razorEngine, targetProjectDirectory);
foreach (var result in results)
{
File.WriteAllText(result.FilePath, result.GeneratedCode);
}
Console.WriteLine();
Console.WriteLine($"{results.Count} files successfully generated.");
Console.WriteLine();
return 0;
}
6.Now we have our own generator and can compile views
7.Create a Razor View (.cshtml)
8.run our generator to compile view:
dotnet run --project .\MyRazorPageGenerator\MyRazorPageGenerator.csproj Croc.XFW3.Web .\Middleware
here I assume that the view is inside Middleware\Views folder.
9.Generator creates a file like ErrorPage.Designer.cs (if view was ErrorPage.cshtml) which we can use:
public async Task Invoke(HttpContext context)
{
try
{
await _next.Invoke(context);
if (context.Response.StatusCode == StatusCodes.Status404NotFound)
{
var statusCodeFeature = context.Features.Get<IStatusCodePagesFeature>();
if (statusCodeFeature == null || !statusCodeFeature.Enabled)
{
if (!context.Response.HasStarted)
{
var view = new ErrorPage(new ErrorPageModel());
await view.ExecuteAsync(context);
}
}
}
}
}
Here we're returning our view in case of 404 error and absense of StatusCodePagesMiddleware. Can be useful for embedded UI in libs.
The generated code uses staff which should be added into your project. To get it we need to acquire nuget package Microsoft.Extensions.RazorViews.Sources. Again it’s not on nuget.org so we need to install it from https://dotnet.myget.org/feed/aspnetcore-dev/package/nuget/Microsoft.Extensions.RazorViews.Sources.

Startup.cs error (ASP.Net Core configuration)

I am trying to set up an ASP.Net Core application to read in configuration settings from a json file. I am using VS2015 and .NetCore 1.0 (with .Net Core Tools preview 2). I am having problems getting a simple piece of boiler plate code to compile.
I am using the following code, which was published at
http://asp.net-hacker.rocks/2016/03/21/configure-aspnetcore.html
public Startup(IHostingEnvironment env)
{
// Set up configuration sources.
var builder = new ConfigurationBuilder()
.AddJsonFile("appsettings.json")
.AddEnvironmentVariables();
if (env.IsDevelopment())
{
// This will push telemetry data through Application Insights
// pipeline faster, allowing you to view results immediately.
builder.AddApplicationInsightsSettings(developerMode: true);
}
Configuration = builder.Build();
}
However, the IDE/compiler complains that 'the name "Configuration" does not exist in the current context' (last line of code). The only suggestion from the IDE is to include Microsoft.Extensions.Configuration. However this is a namespace which does not contain an object or property named "Configuration".
In addition 'AddApplicationInsightsSettings' fails with does IConfigurationBuilder not contain a definition for AddApplicationInsightsSettings and no extension method AddApplicationInsightsSettings accepting a first argument of type IConfigurationBuilder could be found
Any suggestions please ?
Thanks
Simply add Configuration property to your Startup class, tutorial has missed this 'step':
public IConfigurationRoot Configuration { get; set; }
ConfigurationBuilder.Build() method just returns instance of IConfigurationRoot, that you should save, if need to get settings further in Startup class (in ConfigureServices method for example).
Regarding second error, looks like you didn't add the Application Insights dependency:
{
"dependencies": {
"Microsoft.ApplicationInsights.AspNetCore": "1.0.0"
}
}

Error while building fat jar for deploying my jar to remote Cluster

I have set up a single node cluster and trying to deploy my sample topology to it .
I believe to deploy my topology to cluster I have to submit the jar with all dependencies to the Cluster .
For that I created a sample project and added a simple topology to it .
While generating the fat jar using gradle I am seeing this error
gradle fatjar gives below error
Could not expand ZIP '/Users/agarg/.gradle/caches/modules-2/files-
2.1/org.apache.storm/storm-
core/0.9.5/d2bf27db853347dcf66990b4514db20a7897303e/storm-core-0.9.5.jar'.
Could not copy zip entry /Users/agarg/.gradle/caches/modules-2/files-
2.1/org.apache.storm/storm-
core/0.9.5/d2bf27db853347dcf66990b4514db20a7897303e/storm-core-
0.9.5.jar!META-INF/license/LICENSE.base64.txt to '/Users/agarg/Documents/notificationRepo/sample/build/tmp/expandedArchives/storm-
core-0.9.5.jar_366us3312tpl54tci2fld83fij/META-INF/license/LICENSE.base64.txt'.
Here is my build.gradle file fo reference :
dependencies {
compile group: 'clj-stacktrace' , name: 'clj-stacktrace',version: cljStackTrace
compile group: 'org.apache.storm' , name: 'storm-core',version: stormVersion
}
task fatJar(type: Jar) {
manifest {
attributes 'Implementation-Title': 'Gradle Jar File Example',
'Implementation-Version': version,
'Main-Class': 'storm.topology.ExclamationTopology'
}
baseName = project.name + '-all'
from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
with jar
}
buildscript {
repositories {
mavenCentral()
maven { url 'http://repo.spring.io/snapshot' }
maven { url 'http://repo.spring.io/milestone' }
maven { url "https://clojars.org/repo/" }
maven { url "http://repo.maven.apache.org/maven2" }
}
}
Can nyone help me what is going wrong here ???
Thanks In Advance
I am not familiar with gradle, however, you do not need to include "storm-core" or transitive dependencies in your fat jar. It is sufficient if your far jar contains Spout and Bolt classes (and maybe some 3rd party libraries you are using that are not part of Storm)

Gradle dependency on project for all configurations

I'm looking into using Gradle instead of Ant/Ivy. I'm trying to create dependencies between my projects for all configurations, so that for example, project1.compile depends on project2.compile, project1.runtime depends on project2.runtime, etc.
In Ivy, I did this with the following XML:
project1/ivy.xml
<dependency conf="*->#" org="myorg" name="project2" rev="latest.integration" />
In Gradle, here's what I have tried:
project1/build.gradle
configurations.each { config ->
config.dependencies.add project(path: ':project2', configuration: config.name)
}
But it complains that the project function doesn't exist:
> Could not find method project() for arguments [{path=:project2, configuration=archives}] on project ':project1'.
Any ideas how to do this?
configurations.all { config ->
project.dependencies.add(config.name,
project.dependencies.project(
path: ':project2', configuration: config.name))
}
To anyone looking for a working answer to the same question in 2023:
configurations.all {
withDependencies {
add(
project.dependencies.module("org.example:example-artifact:0.0.1") // external dependency
)
add(
project.dependencies.platform("org.example:example-bom:0.0.1") // platform BOM
)
add(
project.dependencies.project(":project2") // project submodule
)
}
}