.app domain package name for android application - java

I have a .app domain registered and wanted to rename android application package with .app in the part, however after I changed the package name to .aap to .app view binding is not working and can't import R class

There are two possible causes of this issue:
Incorrect Import
Build cache issue.
Incorrect Import
Generally, the ViewBinding classes are generated using the ApplicationID specified in AndroidManifest and build.gradle file.
So, there is a chance, when you changed the application ID (a.k.a. packages), the import statements for those packages are not updated.
Just update those import statements with correct package names and you are good to go.
Build cache issue
This is a common issue of build cache. Generally, the ViewBinding is created based on your Application ID specified in AndroidManifest and build.gradle file.
When you update the package name, the build cache is sometimes marked as dirty (i.e. invalid or expired). Which doesn't allow you to access some auto generated classes like ViewBindings/DataBindings/Dependency injection classes.
The only solution for this problem is performing a clean build as follow:
In this Android Studion, from the menu click on Build -> Rebuild Project.
From terminal, in your project directory perform ./gradlew clean build.
In case your project build is failing, try to temporarily comment the code base causing the build failure and try above steps again. Once your build is successful, you can now revert back the commented changes. (NOTE: While uncommenting the codebase, make sure import statements are correct, i.e. they are using the latest package name).

Related

How to run only one (current) file and ignore others in intellij gradle project?

This must be a very simple task for many of you. Let me explain the scenario.
I recently started practicing questions on HackerRank. But, I found the platform not so friendly for debugging. No online platform is or can be because of its own limitations. HackerRank provides question and stub code for many of the problems on its problem page.
For example, let us consider, https://www.hackerrank.com/challenges/java-datatypes/problem
But, because of it's debugging limitations I can't make the best use of portal. Hence, I wrote a PHP script to scrape all the content from the website and generated problem statements in HTML/PDF formats and solutions in java format.
Here's the GitHub project for the same.
https://github.com/saint1729/hr-idea-integration
The main intention of this activity is to have an integration of the website with an IDE like Intellij IDEA. This is now complete.
I created a gradle project with existing sources. But, the project contains many java files (almost 500+ files and each file has it's own main method). My intention is to solve one problem at a time and see if it compiles and submit it using a REST API provided by HackerRank.
But, when I am trying to Right Click and Click on Solution.main() for every file, it tries to compile all files in the project and because there are some compilation issues with the project, I am unable to test my code for the current file. This is not productive for me.
Please let me know if it's possible to compile and run a single file in IDEA (without compiling the whole project). If the idea of creating a gradle project for this activity is not necessary, can somebody recommend me another efficient solution?
NOTE: Every scraped java file contains it's own main method. I know that a project can contain only 1 main method. But, I don't know a coherent solution to solve my problem.
If you want to continue using gradle, you create a module per solution.
Let's suppose you have 3 solutions. canyouaccess, duplicateword and java1darray.
So your repository looks like this:
java
canyouaccess
src/main/java
package
Solution.java
duplicateword
src/main/java
package
Solution.java
java1darray
src/main/java
package
Solution.java
build.gradle
settings.gradle
Each module can have its own main. Inside a settings.gradle file the modules can be defined or disabled by commenting it out.
Your build.gradle looks like this:
...
subprojects { project ->
apply plugin: "java"
sourceCompatibility = 11
}
...
For the settings.gradle looks like this:
include 'java:canyouaccees'
include 'java:dublicateword'
include 'java:java1darray'
Each module can be build separately, you could even group modules by creating a sub module structure.
And each module can have it's own debug configuration, where the module and the main is selected. If your set them as shared, they are stored in xml format under .idea/runConfigurations. So your script can create them as well.
Each module needs it's own gradle.build file, where the main class is declared.
jar {
manifest {
attributes('Main-Class': 'your.main.class.goes.here')
}
}
Something like this should do.

How to import Thrift into Java program?

I’m writing a Java-programm for school that also uses Thrift.
The problem is not so much the general programm/programm-logic itself, but just importing Thrift (to use it in a specific part).
My basic -possibly wrong- understanding is that you write the programm-code (here empfaenger.java), then you import Thrift into this file by adding the needed import-statements, e.g.:
import org.apache.thrift.TException;
import org.apache.thrift.protocol.TBinaryProtocol;
import org.apache.thrift.protocol.TProtocol;
import org.apache.thrift.transport.TSocket ;
import org.apache.thrift.transport.TTransport;
and adding a file in the same directory from which they can actually can be imported, in this case libthrift-0.13.0.jar.(1) Then you later also import a compiled .thrift-file with the language-specific realization oft he IDL-code, that iself again imports some Thrift-classes. This file is here named syncautohersteller.
EDIT: The approach with the .jar-file was recommended by the prof.
Current project-structure (as seen in InteliJ):
The problem is now just that all the Thrift import-statements all throw errors, e.g.
empfaenger.java
java: package org.apache.thrift does not exist
syncautohersteller
package javax.annotation does not exist
so clearly i’m doing something wrong.
Does anybody know how to fix this?
(1) I got the file from the Thrift folder (Home/Downloads/thrift-0.13.0/lib/java/build/libs and then the first of the three .jar-files in the folder) after installing Thrift using ./configure, sudo make and sudo make install and trying to verify by running “~/Downloads/thrift-0.13.0$ thrift –version” with result
Thrift version 0.13.0
In IntellJ Idea to add external Jars you can find some useful information in this question: Correct way to add external jars (lib/*.jar) to an IntelliJ IDEA project.
I suggest you to manage the project's dependencies through Maven, which help you to add JAR dependencies to the classpath in a simpler way.
First, you have to convert your project into a Maven project as explained in IntelliJ Idea documentation.
Then you can follow these steps:
Go to Maven repository website
Search for Thrift
Select first result
Select the version you need
Copy the maven dependency
org.apache.thrift
libthrift
0.13.0
Add maven dependency to your pom.xml file
Execute a mvn clean install, after clicking the following button in IntelliJ
This process will help you and people which work with you to manage in a simpler way the dependencies of the project.
You can do it the simplest way with the Gradle, something like this:
build.gradle.kts:
repositories {
mavenCentral()
}
dependencies {
implementation("org.apache.thrift:libthrift:0.13.0")
}

Why are my Alexa Skills Kit dependencies missing?

I cloned Amazon's ASK java repository on github and ran
mvn package
on it, and it produced the following .jars:
ask-sdk-core-2.3.4.jar
ask-sdk-apache-client-2.3.4.jar
ask-sdk-dynamodb-persistence-adapter-2.3.4.jar
ask-sdk-lambda-support-2.3.4.jar
ask-sdk-servlet-support-2.3.4.jar
ask-sdk-2.3.4.jar
I noticed that when attempting to make certain imports for classes on https://developer.amazon.com/docs/custom-skills, such as import com.amazon.speech.speechlet.servlet.SpeechServlet;
I received a message stating that com.amazon.speech could not be resolved, indicating that the file didn't exist. However, after further investigation, I noticed that there was a SkillServlet class that seemed to essentially replace the SpeechServlet class as it was able to do everything that SpeechServlet could,
so I assumed that the developer site hadn't been updated yet to reflect the changes. I then noticed that RequestHandler, a class in the repository, had a method that returned an object of type Optional< Response >. When I tried to import Response with the following import:
import com.amazon.ask.model.Response;
I recieved an error message stating The type com.amazon.ask.model.Response cannot be resolved. It is indirectly referenced from required .class files
This suggests that the class definition doesn't exist in the project's classpath, despite having included all of the above .jars. I searched through and was unable to find a model directory. Did my maven build fail, and am I missing any .jars? I'm using Eclipse EE IDE, which I know is susceptible to errors, but I've cleaned my project as well as restarted the IDE to no avail.
Update:
I noticed that the pom.xml file within the ask-sdk-core-2.3.4 directory contained a dependency for ASK SDK Model, but it doesn't seem to be obtaining the dependency. I also noticed that though ask-sdk-2.3.4 should also include everything that ask-sdk-core-2.3.4 does, as the latter is listed as a dependency in the former, I have to include ask-sdk-core's jar file separately or Eclipse is not able to recognize certain classes. I think this means that maven has failed, so I just downloaded the jar directly from mvnrepository.com. Any idea why this might have happened?
If you use ask-sdk-2.3.4.jar, then it should include all the dependencies you need like you noticed in your update blurb. When you look at Hello World sample in their Github repo, the pom.xml only contains ask-sdk-2.3.4.jar but not other dependencies that ask-sdk-2.3.4.jar has in it. https://github.com/alexa/alexa-skills-kit-sdk-for-java/blob/2.0.x/samples/helloworld/pom.xml
To your error message on Response, that is because you are missing ask-sdk-model jar which you can find from maven central. http://central.maven.org/maven2/com/amazon/alexa/ask-sdk-model/
I would suggest using maven and pom.xml so that you don't have to download jars individually.

Maven Deployment package and upload to AWS-Lambda

I'm facing issue in uploading the maven deployment package to Amazon s3.
From Eclipse, I'm able to generate the .jar file successfully, however I'm facing issue in uploading to server.
Here is my Java code:
package main.java.mavantestproj;
import java.util.Map;
import com.amazonaws.auth.profile.ProfileCredentialsProvider;
import com.amazonaws.regions.Regions;
import com.amazonaws.services.dynamodbv2.AmazonDynamoDBClient;
import com.amazonaws.services.lambda.runtime.Context;
public class LambdaFunctionHandler {
public String handleRequest(Map<String,Object> input, Context context) {
context.getLogger().log("Input: " + input);
AmazonDynamoDBClient client = new AmazonDynamoDBClient(new ProfileCredentialsProvider("mytest"));
client.setRegion(com.amazonaws.regions.Region.getRegion(Regions.US_WEST_2));
client.describeTable("ProductCatalog");
// TODO: implement your handler
return null;
}
}
in target folder i have got 2 jar's. ie lambda-java-example-1.0-SNAPSHOT.jar & original-lambda-java-example-1.0-SNAPSHOT.jar
In this first jar is 35MB & second one is 4KB. I'm not getting which one to upload to S3 to run my lambda function.
You definitely need the large "uber-jar" so your dependency classes will be included, but there is an alternative way to package things up for AWS-Lambda using the Maven assembly plugin instead of the Shade plugin. You end up with an AWS lambda deployment package in .zip format instead of a single .jar file. It will look a little more like a JEE .war file with all the original .jar dependencies kept intact, and you can include other stuff like properties files that end up unpacked in the file-system where the lambda runs (which may be a little easier to find and load in your code). If you're interested in the details, there's a blog post about it here: http://whirlysworld.blogspot.com/2016/03/aws-lambda-java-deployment-maven-build.html Also, packaging a Lambda function app this way makes it WAY easier to peek into the zip file and figure out which dependency jars are being included, and then identify the ones you might be able to exclude.
This still doesn't get Maven to handle the actual deployment of the package to AWS (create or update). Deploying, and capturing the deployment info (ARN, API-gateway app-id-url, etc.), seems to be the next thing for which Amazon hasn't provided a very clear answer or solution.
The larger JAR file that is being generated includes all of the library dependencies baked in. This is the one you will want to upload to S3 for use by AWS Lambda as these dependencies are required to run.
If you want to make this file smaller you can ensure you are only including libraries you need and remove any unnecessary ones. A common way to do this is with the AWS SDK only include the libraries for the specific services you need to call such as DynamoDB instead of including the entire AWS SDK.
It seems standalone jar file built using shade plugin is sufficient as per this AWS documentation

How to add and use MarkdownView android library

I am on Android Studio 1.5.1
falnatsheh/MarkdownView
In the project's readme at github its gives instructions for use. These don't cover actually adding the project .. and I am learning Android programming (in fact I am making an app to keep my notes, as a sort of second step after "hello world").
how do I add it to the project so that I can follow the instructions on the project's readme? My default attempt was to follow these instructions:
File -> New -> Import Module .. add as ":markdownview" in my case, add it to the app's build.gradle, and then that should be it according to the site.
But that doesn't work:
The project's readme starts by saying you should add "compile 'us.feras.mdv:markdownview:1.1.0'" to the dependencies file (I am assuming they mean the Module:app one)... which looks like another way to add ":markdownview" to me.. but I did that too (and that instead of the ":markdownview"). Still the symbol does not resolve.
how do I add it to the project so that I can follow the instructions on the project's readme?
Add the following to your app/build.gradle file:
dependencies {
compile 'us.feras.mdv:markdownview:1.1.0'
}
which looks like another way to add ":markdownview" to me
Not exactly, but close.
but I did that too (and that instead of the ":markdownview"). Still the symbol does not resolve.
As with everything else in Java, you need to add an import statement.
I just created a scrap project in Android Studio, accepting all defaults in the new-project wizard. I pasted the above snippet in app/build.gradle and let Android Studio sync with the project files. I then added a reference to MarkdownView in the Java file, and Android Studio picked up the import without issue.

Categories

Resources