Monday, March 26, 2018

Resolving Maven "trustAnchors parameter must be non-empty" error

I encountered this Maven error on a new Ubuntu 18.04 system while trying to perform a mvn build on a Google AppEngine project. A screenshot of the error message is shown below.


It seems to be complaining about some "java.security.InvalidAlgorithmParameterException: the trustAnchors parameter must be non-empty" error.

After trying out some suggestions about regenerating Java security certificates, which didn't work, I managed to resolve the problem by creating a Maven  settings.xml file under a hidden folder .m2 underneath the user's home directory.

An example settings.xml file is shown below.

<?xml version="1.0" encoding="UTF-8"?>
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0                            http://maven.apache.org/xsd/settings-1.0.0.xsd">
   <localRepository>/home/yourname/.m2/repository</localRepository>
   <interactiveMode />
   <usePluginRegistry />
   <offline />
   <pluginGroups />
   <servers />
   <mirrors />
   <proxies>
      <!-- 
               <proxy>
      <id>default</id>
      <active>true</active>
      <protocol>http</protocol>
      <host>proxy-host</host>
      <port>8080</port>
      <username>user</username>
      <password>password123</password>
      <nonProxyHosts>localhost,127.0.0.1</nonProxyHosts>
    </proxy> -->
   </proxies>
   <activeProfiles>
      <!--make the profile active all the time -->
      <activeProfile>securecentral</activeProfile>
   </activeProfiles>
   <profiles>
      <profile>
         <id>securecentral</id>
         <!--Override the repository (and pluginRepository) "central" from the
                     Maven Super POM -->
         <repositories>
            <repository>
               <id>central</id>
               <url>http://repo1.maven.apache.org/maven2/</url>
               <releases>
                  <enabled>true</enabled>
               </releases>
            </repository>
         </repositories>
         <pluginRepositories>
            <pluginRepository>
               <id>central</id>
               <url>http://repo1.maven.apache.org/maven2/</url>
               <releases>
                  <enabled>true</enabled>
               </releases>
            </pluginRepository>
         </pluginRepositories>
      </profile>
   </profiles>
</settings>
Change the localRepository tag from /home/yourname/.m2/repository to correct location of your Maven repository.

Then place this the settings.xml file in the following location /home/your_user_id/.m2/

Now when running Maven build commands, the error messages no longer appear.


Wednesday, March 7, 2018

Fixing "Cannot resolve symbol Theme" error in Android Studio

If you have ever encountered unusual "cannot resolve symbol" messages with regards to Android resource XML files (an example is the screenshot below), which cannot be resolved by running Android Studio's Build | Clean Project or Build | Rebuild Project menu commands, then fixing the issue is very simple.


To resolve the problem, click on the Sync Project with Gradle Files icon in Android Studio, as shown in the screenshot below, or select Tools | Android | Sync Project with Gradle Files

Processing files will appear and at the end of it, the error messages no longer appear, as shown below.